Add a row to a treelist

4 posts, 0 answers
  1. Kenneth
    Kenneth avatar
    27 posts
    Member since:
    Nov 2010

    Posted 28 Jul 2015 Link to this post

    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.
  2. Alexander Popov
    Admin
    Alexander Popov avatar
    1416 posts

    Posted 30 Jul 2015 Link to this post

    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!
     
  3. Kendo UI is VS 2017 Ready
  4. Kenneth
    Kenneth avatar
    27 posts
    Member since:
    Nov 2010

    Posted 30 Jul 2015 in reply to Alexander Popov Link to this post

    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

  5. Alexander Popov
    Admin
    Alexander Popov avatar
    1416 posts

    Posted 03 Aug 2015 Link to this post

    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!
     
Back to Top
Kendo UI is VS 2017 Ready