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

Add a row to a treelist

3 Answers 426 Views
TreeList
This is a migrated thread and some comments may be shown as answers.
Kenneth
Top achievements
Rank 2
Kenneth asked on 28 Jul 2015, 02:59 PM
I try to add a new row to a treelist. Is the following code a good procedure?:

Call this: tree.editRow(parentCell);

Then I have a function on treelist edit:
private OnEdit(e: kendo.ui.TreeListEditEvent) {
  e.model['id'] = -1;  //A new, unique and temporarily id
  tree.dataSource.add(e.model);
  tree.saveRow();
}

If I edit the new row before it is saved to the server, I have to do this to confirm the change:
tree.dataSource.add(e.model);
tree.saveRow();

But if the row already has been saved, I only need to do this:
tree.saveRow();

Is this the procedure? (the procedure is okay with me, but it could be there where a better way)
Please ask, if I’m not clear.

3 Answers, 1 is accepted

Sort by
0
Alexander Popov
Telerik team
answered on 30 Jul 2015, 08:20 AM
Hello Kenneth,

Usually the ID is assigned on the server, however this could be done on the client-side as well. This is easily achieved by using custom JavaScript functions to handle the CRUD operations (see example). I am not sure why the DataSource's add method is used on an existing record though. Calling the saveRow in the edit event handler is also a bit odd. Sharing more details about your scenario as well as all related code would help us give you more specific advice.

Regards,
Alexander Popov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Kenneth
Top achievements
Rank 2
answered on 30 Jul 2015, 02:02 PM

Thank you for your reply Alexander and your examples. I understand your questions to my code - I should have made it more clear from the beginning.

I have made this example that shows my code, and hope you will take a look at it.

Regards from Kenneth

0
Alexander Popov
Telerik team
answered on 03 Aug 2015, 10:59 AM
Hello again,

I reviewed the example you shared and while it works I cannot guarantee that there won't be any unexpected results. The recommended approach is to build custom functions that handle the CRUD operations, in a manner similar to the one shown in the example I shared previously. 

Regards,
Alexander Popov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
TreeList
Asked by
Kenneth
Top achievements
Rank 2
Answers by
Alexander Popov
Telerik team
Kenneth
Top achievements
Rank 2
Share this question
or