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?

1 Answer 5306 Views
Grid
Logan
Top achievements
Rank 1
Veteran
Logan asked on 11 Sep 2013, 01:13 PM
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

1 Answer, 1 is accepted

Sort by
0
Kiril Nikolov
Telerik team
answered on 11 Sep 2013, 01:35 PM
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!
Logan
Top achievements
Rank 1
Veteran
commented on 11 Sep 2013, 01:43 PM

That looks like it will do what I need.
 thanks!
Kiril Nikolov
Telerik team
commented on 11 Sep 2013, 01:51 PM

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!
Logan
Top achievements
Rank 1
Veteran
commented on 12 Sep 2013, 12:28 PM

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
Kiril Nikolov
Telerik team
commented on 12 Sep 2013, 12:44 PM

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!
Logan
Top achievements
Rank 1
Veteran
commented on 12 Sep 2013, 12:56 PM

That was exactly what I was looking for.
Thanks,
~Logan
Curt Rabon
Top achievements
Rank 1
Veteran
commented on 24 Jun 2015, 07:25 PM

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.

Kiril Nikolov
Telerik team
commented on 25 Jun 2015, 10:42 AM

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!
 
Curt Rabon
Top achievements
Rank 1
Veteran
commented on 25 Jun 2015, 03:00 PM

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?

Kiril Nikolov
Telerik team
commented on 29 Jun 2015, 05:56 AM

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!
 
Tags
Grid
Asked by
Logan
Top achievements
Rank 1
Veteran
Answers by
Kiril Nikolov
Telerik team
Share this question
or