Is there an event that first after a user edits a cell but before they save in a grid with batch edit and incell editing?

11 posts, 1 answers
  1. Logan
    Logan avatar
    32 posts
    Member since:
    Apr 2013

    Posted 11 Sep 2013 Link to this post

    I have a need to do some calculations and possibly prevent saving on a grid (with the dirty data) as it is being edited but before it is saved.  I don't see any events that fit that need.  I was hoping I was missing something or that there was an accepted work around.

    I am working in MVC, but I have put together a jsFiddle example at http://jsfiddle.net/UDX3L/21/

    Thanks,
    ~Logan
  2. Kiril Nikolov
    Admin
    Kiril Nikolov avatar
    2566 posts

    Posted 11 Sep 2013 Link to this post

    Hi Logan,

    I am not exactly sure what do you want to achieve, but you can use the save event of the grid (fired when the focus is moved outside of the cell being edited and before the cell is closed), here you can use the event object to prevent the change of the value if it does not match your criteria. Otherwise I would suggest the saveChanges event which is fired when the user press the save button.

    You can take a look at the following API reference showing all the events, that the grid fires:

    http://docs.kendoui.com/api/web/grid#events-cancel
     
    Regards,
    Kiril Nikolov
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Kendo UI is VS 2017 Ready
  4. Logan
    Logan avatar
    32 posts
    Member since:
    Apr 2013

    Posted 11 Sep 2013 Link to this post

    That looks like it will do what I need.
     thanks!
  5. Answer
    Kiril Nikolov
    Admin
    Kiril Nikolov avatar
    2566 posts

    Posted 11 Sep 2013 Link to this post

    Hello Logan,

    I am glad that you find my post helpful. 

    Please do not hesitate to contact us again, if you have any other questions.
     
    Regards,
    Kiril Nikolov
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  6. Logan
    Logan avatar
    32 posts
    Member since:
    Apr 2013

    Posted 12 Sep 2013 Link to this post

    Kiril,
    The event appears to be working as needed, but now I need to be able to cancel the change and either:
    1) revert it back to the original value (or a blank value) but with without any ui indication that it is dirty and will be saved.
    2) leave the invalid value, but highlight the box (maybe set the background to red) and remove any ui indication that it is dirty and will be saved.

    I have tried changing the value and setting dirty to false on both the e.model and the appropriate data row on e.sender._data with no success.

    My current non working code is:
    function checkSave(e)
    {
        var val = CheckGrade(e.model.GradingOption, e.values.FinalGrade, e.model.PreliminaryGrade);
        if(val.length > 0)
        {
            var data = e.sender._data;
            for (var i = 0; i < data.length; i++)
            {
                var row = data[i];
                if (row.id == e.model.id) {
                    row.dirty = false;
                    row.FinalGrade = '?';
                }
            }
            alert(val);
            e.model.dirty = false;
            e.model.FinalGrade = '?';
            return true;
        }
        return false;
    }

    Thanks  for all of the help,
    ~Logan
  7. Kiril Nikolov
    Admin
    Kiril Nikolov avatar
    2566 posts

    Posted 12 Sep 2013 Link to this post

    Hello Logan,

    Is this what you are looking for?

    http://jsbin.com/evIYIHu/1/edit

    With this the grid will not allow you to enter values bigger than 10.
     
    Regards,
    Kiril Nikolov
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  8. Logan
    Logan avatar
    32 posts
    Member since:
    Apr 2013

    Posted 12 Sep 2013 Link to this post

    That was exactly what I was looking for.
    Thanks,
    ~Logan
  9. Curt Rabon
    Curt Rabon avatar
    45 posts
    Member since:
    Dec 2008

    Posted 24 Jun 2015 Link to this post

    Is there a way to get the save event to fire when using a custom editor that does not have any data-bound inputs?

    I'm also using batch/incell editing with version 2015.2.624.

    I have multiple HTML inputs in a custom editor, so I can't use data-bind="" syntax because I need to manually set the model value using the correct input value when the user moves away from the edited cell.  I can put a button/span that says "apply" or "save" that the user clicks in the cell and then in that Javascript function I can find the model object and field name programmatically, and save the model (this works fine).  But I would like to do it when the user moves away from the cell, because having 1 column use something the user clicks on the save the cell looks odd when my other columns are not that way.

     In a custom editor when no input uses the data-bind syntax, then the save event doesn't fire when moving away from the cell.

  10. Kiril Nikolov
    Admin
    Kiril Nikolov avatar
    2566 posts

    Posted 25 Jun 2015 Link to this post

    Hello Curt Rabon,

    There is no way for the grid to fire the save event in your case. You can manually trigger it using the jQuery trigger() method. If you have any other questions, please open a separate support ticket and we will be happy to assist you.

    Regards,
    Kiril Nikolov
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  11. Curt Rabon
    Curt Rabon avatar
    45 posts
    Member since:
    Dec 2008

    Posted 25 Jun 2015 in reply to Kiril Nikolov Link to this post

    Internally you call CloseCell() to close the editor when focus is moved away.  You already have the model object.  All you would have to do is add a simple CellClose event for those of us that use complex custom editors.  This would allow us to do model adjustments or "cleanup" when the cell is closing.

     Would you please consider adding this event?

  12. Kiril Nikolov
    Admin
    Kiril Nikolov avatar
    2566 posts

    Posted 29 Jun 2015 Link to this post

    Hello Curt Rabon,

    You can submit this as a feature request on UserVoice, so that it is considered for implementation in a future release.

    Regards,
    Kiril Nikolov
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
Back to Top
Kendo UI is VS 2017 Ready