This is a migrated thread and some comments may be shown as answers.

Kendo Grid Save Event datasource problem

1 Answer 156 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mario
Top achievements
Rank 1
Mario asked on 27 Mar 2014, 03:54 PM
OK, this is what I need:

I need to do some complex calculations every time when user edits any cell of two of the specific Columns. Let's Say User can edit Columns A and B, but C is read only and calculated by my custom function.. C is also designed like this
template: kendo.template("<span class='columnC'></span>")
OK, I need to loop through all of the A and B columns every time when any of those cells is edited..
My problem is that if I do it on "save" event, when I loop through the dataSource.view() elements I got the old value for the cell which user just edited.. I assume that this is because the dataSource is not synced yet with the user input.. This makes my calculation wrong and it's not acceptable.

If I do it on "change" event it works fine but then it's called too many times unnecessarily and it does stress the client's cpu.

Is there a way under the "save" event to force the dataSource update and then do some things when the new values are stored into dataSource?
I'd like to avoid something like this:
"this.dataSource.getByUid(e.model.uid).set("ColumnA",e.model.ColumnA);"
"this.dataSource.getByUid(e.model.uid).set("ColumnB",e.model.ColumnB);"

as I don't know what is the cell which the user has changed.. ColumnA or ColumnB.. Maybe there is a simple way around this..

Help pls

1 Answer, 1 is accepted

Sort by
0
Vladimir Iliev
Telerik team
answered on 31 Mar 2014, 12:08 PM
Hi Mario,

I would suggest to use the "change" event of the grid dataSource to update column "C" based on columns "A" and "B" - please check the optimized example below:

function onChange(e) {
    if (e.action == "itemchange") {
        if (e.field == "ColumnA" || e.field == "ColumnB") {
            if (e.items[0] && (e.items[0].ColumnA == 0 || e.items[0].ColumnB == 0)) {
                e.items[0].set("ColumnC", true);
            }
 
        }
    }
},

Using the above example the column "C" will be updated only when it's needed. 

Regards,
Vladimir Iliev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
Mario
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
Share this question
or