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

New Batch Editing modified cell count

2 Answers 95 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Massimiliano
Top achievements
Rank 1
Massimiliano asked on 13 Jul 2013, 09:10 PM
I'm struggling to find a way to retrieve if any cell has really been modified through batch editing.
I'd like to show the SAVE CHANGES and CANCEL CHANGES buttons, only if some editing really took place.
I already found to show/hide a button inside a toolbar in the Command Item template but I'm struggling to know if is there any cell that have been modified (when the little red triangle in the corner appear).
I went down to the ._changes object but with no much luck since the object is empty at start but if you modify a cell and then revert it back to initial value, the ._changes object is no more empty even if no red triangles appear and no batch editing happened after all.

Here is what I come up with so far (but it doesn't work for the reason above):

function ShowBatchUpdateButton() {
    var toolBar = $find("RadToolBar1");
    var button = toolBar.findItemByText("Nuovo");
    var grid = $find("<% = RadGrid1.ClientID %>");
    if (!jQuery.isEmptyObject(grid.get_batchEditingManager()._changes)) {
        button.set_cssClass("ShowGridCommandBarButton")
    } else {
        button.set_cssClass("")
    }
}

How can I spot if there are any red marks on the grid? (because this is what I'm looking for to show/hide the UPDATE and CANCEL buttons in real time)

2 Answers, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 18 Jul 2013, 06:02 AM
Hello Massimiliano,

As you have found out, ._changes object does not remove elements when a cell is modified back to its original value. That is made that way by design and you will not be able to use it in your case.

In order to check if there are any cells with changed values, you could search the grid for elements with rgBatchChanged class. If none exist in the grid you could hide the commands table, or else you could show it.

I have modified your code so that the if/else statement will determine if there are any changes:
function ShowBatchUpdateButton() {
    var toolBar = $find("RadToolBar1");
    var button = toolBar.findItemByText("Nuovo");
  
    var grid = $find("<%= RadGrid1.ClientID %>");
    var gridElement = $(grid.get_id);
    var changes = gridElement.find(".rgBatchChanged");
  
    if (changes.length > 0) {
        button.set_cssClass("ShowGridCommandBarButton")
    } else {
        button.set_cssClass("")
    }
}

If you have any further questions, please feel free to get back to us.
 

Best Regards,
Konstantin Dikov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Massimiliano
Top achievements
Rank 1
answered on 18 Jul 2013, 10:08 AM
Konstantin you are a damn genius!
I would have never thought of looking for the red corner class to count the items!
Thanks that's awesome.

Now I have a general issue with BatchEdit mode triggering errors alltogether but I guess I will open another topic on that subject, to have better references for all other forum users as well.
Thanks again.
Tags
Grid
Asked by
Massimiliano
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Massimiliano
Top achievements
Rank 1
Share this question
or