Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
340
rowAdding event - Access the row
posted

name: "Updating",
locale: {
addRowLabel: "Add new..",
rowEditDialogCaptionLabel: "Add New"
},
enableAddRow: true,
enableUpdateRow: true,
enableDeleteRow: false,
editRowEnding: function (evt, ui) {
console.log(ui);
},
rowAdding: function (evt, ui) {
console.log(ui);
},

I am using the code above. I need to access the row that was added so I can set some values on field that were hidden from the user.

How can I do this?

  • 140
    Offline posted

    Hello William,

    When a column is hidden, no editor is rendered for this column when new row is added. This means that the only way to add particular cell value for this column is to add it the corresponding record from the underlying data source. The new row is pushed on the last position, respectively last record should be modified with the value when rowAdded event is fired.

    Attached you can find a sample that updates the dataSource array when rowAdded event is triggered. “Hidden column” is initially not visible. A row is added and afterwards the column is shown. You can notice that the value for newly added record is set to “default value”.

    Additionally the dataBind method should be used if you want to update the UI with the changes in the dataSource.

    In case you have additional questions don’t hesitate to ask them.

    changeHiddenCellsSample.zip

  • 140
    Offline posted

    Hello William,

    After researching further the best way to change the added record and add value to the hidden columns is by binding to the editRowEnding event. Its ui param has values property which is an object which is the record which will be added in the dataSource array.

    editRowEnding: function (evt, ui) {
        if(ui.rowAdding) {
            ui.values["HiddenColumn"] = "default value";
        }
    },

    I have updated the sample I sent you. You can notice that the value for newly added record is set to “default value”.

    In case you have additional questions don’t hesitate to ask them.
    5076.changeHiddenCellsSample.zip