Reputation: 1603
Is there a way within the datasource that you can specify an Auto ID field within Kendo UI?
I.e. so when we are inserting rows programmatically the id is auto generated. The data is not coming from a remote source. The data is initially empty and rows created by users and stored locally to upload to a remote location at a later date. So we need the datasource to automatically generate an id.
Or will we have to do this programmatically ourselves, by creating a local storage sequence number and manually incrementing?
Upvotes: 1
Views: 3494
Reputation: 12855
There is no way to auto-generate a sequence using the Kendo UI API. You'll have to do this using JavaScript.
Something like this:
function onEdit(e)
{
if (e.model.isNew())
{
//set field
var id = generateId();
e.model.set("Id", id);
}
}
function generateID() {
AutoID = 1; // Get the latest sequential ID for this sector.
if (localStorage.getItem('ID') !== "") {
AutoID = parseInt(localStorage.getItem('ID')) + 1; // Save the new ID
localStorage.setItem('ID', AutoID);
}
return AutoID;
}
Upvotes: 1