Search code examples
kendo-uikendo-datasourcekendo-dropdownkendo-listview

How set id after create new object?


I create custom button on ListView. Then i create new object, new button has null ID. Please see snipet.

Steps:

  1. Click Create.
  2. Fill edit form.
  3. Click save.
  4. Click options and see alert null;

            save: function(e)
            {
                // What i can do this, if i know id here?
                e.model.id = ids++;
            },
    

Solution

  • Typically id is returned by the server but in your example where the DataSource is a local object you can manually assign it but you should assign it to the id not to id. I.e.: in your model definition the id is code (not id) so save function should be:

    save: function(e) {
        e.model.code = ids++;
    },
    

    Your snippet modified here