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

Update All Grid Columns with default value

9 Answers 885 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Naga
Top achievements
Rank 1
Naga asked on 24 Feb 2016, 07:41 PM

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

Sort by
0
Naga
Top achievements
Rank 1
answered on 24 Feb 2016, 07:42 PM
The header should be Update all ROWS of Grid with default value for a column
0
Accepted
Boyan Dimitrov
Telerik team
answered on 26 Feb 2016, 02:42 PM

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
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Naga
Top achievements
Rank 1
answered on 26 Feb 2016, 03:36 PM
Thank you, it worked
0
Naga
Top achievements
Rank 1
answered on 26 Feb 2016, 03:45 PM

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 ?

0
Boyan Dimitrov
Telerik team
answered on 01 Mar 2016, 12:23 PM

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
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Arun
Top achievements
Rank 1
answered on 18 Jul 2017, 09:07 AM

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

0
Boyan Dimitrov
Telerik team
answered on 20 Jul 2017, 06:43 AM

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
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Arun
Top achievements
Rank 1
answered on 20 Jul 2017, 09:28 AM

Thanks Boyan !!

Its working fine now.

0
Arun
Top achievements
Rank 1
answered on 20 Jul 2017, 09:29 AM

Thanks Boyan !

It's working fine now.

Tags
Grid
Asked by
Naga
Top achievements
Rank 1
Answers by
Naga
Top achievements
Rank 1
Boyan Dimitrov
Telerik team
Arun
Top achievements
Rank 1
Share this question
or