i have a requirement with one grid and dropdownlist.
grid has columns ID, Name, Type , Source, Destination
When the destination is empty or when destination column contains double hyphen "--" i need to update the column value to the selected value of the dropdown (this dropdown is not a part of grid)
I tried to provide defaultValue while declaring the model but it dint work, here is the code snippet
schema: {
model: {
fields: {
DestinationLocator: {
type: "string", defaultValue: $("#myDDL").data("kendoDropDownList").text()
}
}
}
I even tried to loop through the Grid and update the column manually, this worked when there are less number of rows, when the Grid has more than 500 rows, the application does not respond.
var grid = $("#myGrid").data("kendoGrid");
var dataitem = grid.dataSource.data();
var destLocText = $("#myDDL").data("kendoDropDownList").text();
for (var i = 0; i < dataitem.length; i++) {
if (dataitem[i].DestinationLocatorID == null || dataitem[i].DestinationLocatorID == '' || dataitem[i].DestinationLocatorID == '--') {
dataitem[i].set("DestinationLocator", destLocText);
}
}
Please help me.
9 Answers, 1 is accepted
Hello Naga,
The defaultValue option of the model field is used only when a new item is created (using the "Add new button" button in the toolbar).
The set method of Model object will refresh the Kendo UI Grid in order to show the updated values. So basically in this case the Kendo UI Grid will be rebound and repainted about 500 times. In this case I would suggest to update the model fields with using "." notation instead of using set method (this will not refresh the Kendo UI Grid). When you are done modifying all models (when you reach the last one) you can call the refresh method of the Kendo UI Grid.
dataitem[i].DestinationLocator = destLocText;
Regards,
Boyan Dimitrov
Telerik
In what scenarios should we use ".set "? using "." notation does the job.
Also is Grid refresh mandatory for all data changes after grid is loaded ?
Hello Naga,
If you use "." notation you have to refresh the Kendo UI Grid manually in order to repaint the grid and display the updated values. The set method will refresh the grid automatically.
Regards,
Boyan Dimitrov
Telerik
Hello Boyan,
Looks, things are working fine with the given solution except save changes.
If i am using "set" then Save Changes is getting called on the click but if i am just assigning the value to dataitem then Save Changes is not getting called on the click.
I want to stored that data into the DB once updated from the Jquery. Below i am pasting my code for the same.
dataitem[i].set('AvailabilityReason', reasonval)
This is working fine instead of dataitem[i].AvailabilityReason = reasonval;
"Set" is very slow as you described in the previous comment and also not good for bulk update but if i click on the Save Changes button then it is working perfectly.
I want to use " dataitem[i].AvailabilityReason = reasonval " but Save button is not working with this update.
Please Help
Regards,
Arun Joshi
Hello,
The reason why save changes is getting called on click when set method is used is because set method internally sets the dirty field of the model to true. The Kendo UI DataSource checks whether the dirty field is true to determine whether the model is modified. In order to use "." notation and force the Kendo UI DataSource treat the item as modified is to change the dirty field to true as well.
Regards,Boyan Dimitrov
Progress Telerik
Thanks Boyan !!
Its working fine now.
Thanks Boyan !
It's working fine now.