New Batch Editing modified cell count

3 posts, 0 answers
  1. Massimiliano
    Massimiliano avatar
    184 posts
    Member since:
    Oct 2012

    Posted 13 Jul 2013 Link to this post

    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. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1800 posts

    Posted 18 Jul 2013 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Massimiliano
    Massimiliano avatar
    184 posts
    Member since:
    Oct 2012

    Posted 18 Jul 2013 Link to this post

    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.
Back to Top