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

Handling the "set" event of model cancels grid "save" event

11 Answers 555 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Todd
Top achievements
Rank 1
Todd asked on 26 Aug 2012, 08:00 PM
Kendo.web.min  v2012.2.710

Is handling the set event of the data-model supposed to prevent the grid's save event from firing??  It does for me.  See here:  http://jsfiddle.net/hvzw7/

Commenting out the set event will allow the save event to fire.

Also, the set event's parameters appear to be 2 separate parameters: the field and the field's value, but the documentation states one parameter with 2 properties (e.field and e.value).

11 Answers, 1 is accepted

Sort by
0
Todd
Top achievements
Rank 1
answered on 06 Sep 2012, 09:21 PM
Is this intentional ?
0
Daniel
Telerik team
answered on 12 Sep 2012, 06:25 AM
Hello Todd,

The Grid save event will not fire because when handling the set function of the model the record is not marked as dirty and the change event is not raised. You should either use the default function or perform the same actions in order for the values to be saved.

Kind regards,
Daniel
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Todd
Top achievements
Rank 1
answered on 12 Sep 2012, 02:11 PM
Thanks Daniel, that makes sense.  Using the model's "set" method will still update the grid's cells, so the save event is only when you made the changes using the grid.

What about the documentation discrepancy I mentioned??

Thanks.
0
Daniel
Telerik team
answered on 17 Sep 2012, 10:07 AM
Hello Todd,

When specifying the set option to the model, you will override the function instead of binding to the "set" event. In order to bind to the event of the observable object you should use code after loading data or in the Grid edit event in this case. For convenience I updated the jsFiddle sample to show the second approach.

Regards,
Daniel
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Todd
Top achievements
Rank 1
answered on 17 Sep 2012, 02:14 PM
Daniel,

Thanks for posting a workaround, but you still haven't answered my question about the documentation discrepancy.  Please answer.  See my first post for details.
0
Daniel
Telerik team
answered on 20 Sep 2012, 01:19 PM
Hello Todd,

I am not sure if I understand correctly the problem with the documentation. The set event of the observable object receives a single parameter which has fields field and value. The set method accepts two parameters the field name and the value. Could you specify where in the documentation it is stated that the set event has two parameters?

Regards,
Daniel
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Todd
Top achievements
Rank 1
answered on 21 Sep 2012, 01:59 AM
I used the wrong term "parameters"...I meant "arguments"....the arguments the set event receives when fired.

http://docs.kendoui.com/api/framework/observableobject#set-event

Under the "Event Data" section of the "Set Event", you see e.field, e.value  ...but the event actually receives 2 different arguments, not 1 argument with 2 properties.  Please see here for proof:

http://jsfiddle.net/hvzw7/

In this jsFiddle, change the product name cell value to something like "cat", and the set event fires, where you can see the 2 different arguments (not one argument "e" with 2 properties).
0
Daniel
Telerik team
answered on 22 Sep 2012, 03:39 PM
Hello again Todd,

As in one of my previous replies I can say, that when specifying the set option to the model like in the jsFiddle sample:

model: {
   set: function(field, fieldValue) {
       log.append('<br />(model set) ' + field + ':  ' + fieldValue);  
   }
you will not bind to the set event but you will override the set method which accepts two parameters.  Regards,
Daniel
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Remco
Top achievements
Rank 1
answered on 08 Nov 2012, 11:00 AM
I assume it's ok to override the set method as long as you call the base set method like so:
kendo.data.ObservableObject.fn.set.call(this, name, value); 

correct? Being able to override the set method is better than handling your own change event.
0
Josh
Top achievements
Rank 1
answered on 01 Dec 2014, 08:57 PM
Is Remco's suggested way to override the set method on an observable an accepted practice or something to avoid?

set: function (name, value) {
    if (name === "stuff") { value = "foo bar"; }
    kendo.data.ObservableObject.fn.set.call(this, name, value);
}
0
Daniel
Telerik team
answered on 04 Dec 2014, 05:07 PM
Hello,

We haven't recommended this approach but it is a possible solution.

Regards,
Daniel
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
Todd
Top achievements
Rank 1
Answers by
Todd
Top achievements
Rank 1
Daniel
Telerik team
Remco
Top achievements
Rank 1
Josh
Top achievements
Rank 1
Share this question
or