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

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

3 Answers 2528 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Remy
Top achievements
Rank 1
Remy asked on 23 Nov 2018, 08:07 AM

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.

3 Answers, 1 is accepted

Sort by
0
Alex Hajigeorgieva
Telerik team
answered on 26 Nov 2018, 02:54 PM
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.
0
Remy
Top achievements
Rank 1
answered on 27 Nov 2018, 01:08 AM
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
0
Alex Hajigeorgieva
Telerik team
answered on 28 Nov 2018, 08:38 PM
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.
Tags
General Discussions
Asked by
Remy
Top achievements
Rank 1
Answers by
Alex Hajigeorgieva
Telerik team
Remy
Top achievements
Rank 1
Share this question
or