We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Always original value in editTemplate

Thread ID:

Created:

Updated:

Platform:

Replies:

119342 Jun 8,2015 09:24 AM Jun 10,2015 08:59 AM JavaScript 3
loading
Tags: ejGrid
Linus Nilsson
Asked On June 8, 2015 09:24 AM

I am trying to create a column that uses a checkbox in edit mode. It works, except that args.rowdata always contains the original values when the write function is called. I select a cell, (un)check the checkbox, and leave the cell. The cell now has the new value. But when I select the same cell again, the cell gets reverted to its original value, since args.rowdata["yesNo"] contains the original value.  Is it a bug, or am I supposed to find the correct value for the checkbox somewhere else?

var data = [
    {
        text: "Hello",
        yesNo: true
    },
    {
        text: "World",
        yesNo: false
    }
];

$("#grid").ejGrid({
    dataSource: data,
    
    editSettings: {
        allowEditing: true,
        editMode: "batch"
    },
    
    columns: [
        {
            field: "text",
            headerText: "Text",
            width: 80
        },
        {
            field: "yesNo",
            headerText: "Yes/No",
            editTemplate: {
                create: function () {
                    return "<input type='checkbox' class='trimmaGridCheckBox' />";
                },
                read: function (args) {
                    // Read checkbox state.
                    return args.prop("checked");
                },
                write: function (args) {
                    // Set checkbox state from row data.
                    args.element.prop("checked", args.rowdata["yesNo"]);
                }
            }
        }
    ]
});

Balaji Marimuthu [Syncfusion]
Replied On June 9, 2015 09:34 AM

Hi Linus,

Thanks for using Syncfusion Products.

We considered the requirement “EditTemplate write function is always Maintained the original value ” as a bug. We have logged a report on this and will fix the issue internally, also the fix will be included in Vol 2 Service Pack release which has been scheduled to be rolled out in the month of July 2015.

We have also created an incident internally to have a follow up with this issue.
We suggest you to use the below workaround solution to resolve your reported issue. Please refer the sample and code snippet below:
Sample: Grid

$("#grid").ejGrid({

            dataSource: data,


            editSettings: {

                allowEditing: true,

                editMode: "batch"

            },

            toolbarSettings: { showToolbar: true, toolbarItems: [ej.Grid.ToolBarItems.Update, ej.Grid.ToolBarItems.Cancel] },


            columns: [

                {

                    field: "text",

                    isPrimaryKey: true,

                    headerText: "Text",

                    width: 80

                },

                {

                    field: "yesNo",

                    headerText: "Yes/No",

                    editTemplate: {

                        create: function () {

                            return "<input type='checkbox' class='trimmaGridCheckBox' />";

                        },

                        read: function (args) {

                            // Read checkbox state.

                            return args.prop("checked");

                        },

                        write: function (args) {

                            // Set checkbox state from row data.

                            obj = $("#grid").ejGrid('instance');

                            val = obj._bulkEditCellDetails.cellValue;

                            args.element.prop("checked", val !== undefined ? val : args.rowdata["yesNo"]);

                        }

                    }

                }

            ]
        });


In the above code, we have assigned the edited cell value to the element in edit template write function.

And in the provided code, you have not enabled the isPrimaryKey property. Please set the isPrimaryKey property as true to edit the records. Please refer the documentation for further details.
http://www.syncfusion.com/kb/2675/cant-edit-any-row-except-the-first-row-in-grid


Please let us know if you have any queries.

Regards,
Balaji Marimuthu

Linus Nilsson
Replied On June 9, 2015 09:53 AM

Thank you! The workaround works.

Balaji Marimuthu [Syncfusion]
Replied On June 10, 2015 08:59 AM

Hi Linus,

Happy that the provided workaround works. Please get back to us for further assistance.

Regards,
Balaji Marimuthu

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;