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

Trying to get batch edit to affect more than one value

2 Answers 53 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Brian
Top achievements
Rank 1
Brian asked on 13 Feb 2013, 04:51 PM
So I have a scenario which I believe should be do-able in some form however I can't seem to figure out how to do it. Take for example the batch editing on the demo page: Batch Demo

Now imagine I've added another column which is now "Total Cost". What I'd like to do is trap on either a change in "Unit Price", or change in "Unit Stock" and be able to update the "Total Cost" field, and mark that as dirty.

I can go into the datasource and alter the value, but it seems when I refresh the grid, the dirty statuses are cleared. Is there a nicer way to do this that I'm missing?

2 Answers, 1 is accepted

Sort by
0
Vladimir Iliev
Telerik team
answered on 15 Feb 2013, 09:18 AM
Hi Brian,

 
Basically you can use the change event of the grid dataSource to check if the currently changed field is one of the required fields to execute your custom code - please check the example below:

Change event:

$("#grid").kendoGrid({
    dataSource: {
        change: onChange

onChange function:
function onChange(e) {
    if (e.field == "UnitPrice" || e.field == "UnitsInStock") {
        //execute your custom code
    }
}

Also please note that currently the grid doesn't support preserving the dirty marks after reloading the grid.
Kind Regards,
Vladimir Iliev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Brian
Top achievements
Rank 1
answered on 15 Feb 2013, 01:26 PM
Yeah, that's what I ended up going with though it wasn't my favorite way to do so...For anyone else with this same problem here's what I did. The only downside is that your field can not have a dirty flag on it, even if you add the k-dirty-cell class it doesn't seem to want to show up for me.
function updateTotals (e) {
     //Get the row and update the datasource
     var row = e.items[0];
     var newTotalVal = row.Col1 + row.Col2 + etc...
     kendoGrid.dataSource.getByUid(row.uid).Total = newTotalVal;
 
     //Now update the UI (Note my last column was the total, your code may need to change)
     //(I also was adding up percentages so you may need to format differently)
     kendoGrid.tbody.find("tr[data-uid='" + row.uid + "']>td:last").html(kendo.toString(newTotalVal, "n1") + "%");
 }
Tags
Grid
Asked by
Brian
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
Brian
Top achievements
Rank 1
Share this question
or