Update All Grid Columns with default value

10 posts, 1 answers
  1. Naga
    Naga avatar
    25 posts
    Member since:
    Jul 2015

    Posted 24 Feb 2016 Link to this post

    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.

  2. Naga
    Naga avatar
    25 posts
    Member since:
    Jul 2015

    Posted 24 Feb 2016 in reply to Naga Link to this post

    The header should be Update all ROWS of Grid with default value for a column
  3. Answer
    Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    2062 posts

    Posted 26 Feb 2016 Link to this post

    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!
     
  4. Naga
    Naga avatar
    25 posts
    Member since:
    Jul 2015

    Posted 26 Feb 2016 in reply to Boyan Dimitrov Link to this post

    Thank you, it worked
  5. Naga
    Naga avatar
    25 posts
    Member since:
    Jul 2015

    Posted 26 Feb 2016 in reply to Boyan Dimitrov Link to this post

    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 ?

  6. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    2062 posts

    Posted 01 Mar 2016 Link to this post

    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!
     
  7. Arun
    Arun avatar
    3 posts
    Member since:
    Jun 2017

    Posted 18 Jul 2017 in reply to Boyan Dimitrov Link to this post

    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

  8. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    2062 posts

    Posted 20 Jul 2017 Link to this post

    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.
  9. Arun
    Arun avatar
    3 posts
    Member since:
    Jun 2017

    Posted 20 Jul 2017 in reply to Boyan Dimitrov Link to this post

    Thanks Boyan !!

    Its working fine now.

  10. Arun
    Arun avatar
    3 posts
    Member since:
    Jun 2017

    Posted 20 Jul 2017 in reply to Boyan Dimitrov Link to this post

    Thanks Boyan !

    It's working fine now.

Back to Top