How to dynamically add the values in kendo Grid in editing state

4 posts, 0 answers
  1. mc
    mc avatar
    2 posts
    Member since:
    Mar 2018

    Posted 23 Nov Link to this post

    In grid, I need to dynamically add a value to a column with a new row using a pop-up box. when I get dataSource I tried this method,

    var firstItem = $('#GridName').data().kendoGrid.dataSource.data()[0];
    firstItem.set('name','The updated Name');

     

    but it was useless.

    In fact, it gets the value given to it, but it doesn't show up,(I guess it's the edit reason,but I don't know how to solve it)

    What should I do to achieve it? Thank you very much. I look forward to your answer.

  2. Alex Hajigeorgieva
    Admin
    Alex Hajigeorgieva avatar
    506 posts

    Posted 26 Nov Link to this post

    Hi,

    There are different approaches that you could take to pass a certain value to new models of the Kendo UI Grid.

    1) The built-in way is with the data source schema model fields defaultValue

    https://docs.telerik.com/kendo-ui/api/javascript/data/model/methods/define

    2) Alternatively, you may define the defaultValue as a function and return a specific value based on the current filters. 

    https://docs.telerik.com/kendo-ui/controls/data-management/grid/how-to/filtering/use-filtering-with-dynamic-default-values

    3) You may add an event handler to the beforeEdit event of the grid and assign the new value with the set() method. The example uses the isNew() method to distinguish the new records from the rest:

    beforeEdit: function(e){
      if(e.model.isNew()){
        e.model.set("name", "Test");
        // alternatively if you do not want to trigger change
        // e.model.name = "Another Test"
      }
    },

    Here is a simple runnable example:

    https://dojo.telerik.com/@bubblemaster/eCEVAQUb

    Let me know in case you have additional questions.

    Kind Regards,
    Alex Hajigeorgieva
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. mc
    mc avatar
    2 posts
    Member since:
    Mar 2018

    Posted 26 Nov in reply to Alex Hajigeorgieva Link to this post

    I'm sorry I didn't make myself clear,
    When I add, the value to be selected is the one that the user selects through the pop-up box, so I cannot use defaultValue or editBefore
  4. Alex Hajigeorgieva
    Admin
    Alex Hajigeorgieva avatar
    506 posts

    Posted 28 Nov Link to this post

    Hi,

    I apologise for not understanding the desired behaviour.

    When the Kendo UI Grid goes into edit mode, it brings up an editable window with editors. Each of the built-in editors is bound to the model property, therefore updating any value in the popup, updates the model dynamically. 

    If the popup form has some custom editors, for example, a DropDownList, then it should be bound to the property - either by setting the name of the respective input or by specifying data-bind="value: PropertyName".

    https://dojo.telerik.com/oPahUYEd

    In case this is not the desired behaviour, could you please explain what is with step by step instructions or screenshots.

    Kind Regards,
    Alex Hajigeorgieva
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top