0
votes

I have used jquery kendo grid for one my project and it is working like a charm.

But the only problem is when i try to add a new record to the kendo grid it is always adding that new record at last place i mean at last row ..

can we have any option to add a new record at first place . This is what i have in my add function

var tr = $(e.target).closest("tr");
 var dataElem = this.dataItem(tr);
 XGrid.gridControl.getKendoObject().dataSource.add(dataElem);

This is always adding the dataelement as a last row in the XGrid. Can we add the same as a first row ??

Thanks in advance

1

1 Answers

0
votes

Use the Insert method dataSource.insert(position, dataobject)

dataSource.insert(0,{
      id: currentId,
      done: false,
      description: $todo.val()
    });

Here is a demo Adding a new Item

Another way around.

'Kendo grid data source is an array of objects(every row data is an object)

So here you can use the Use unshift. It's like push, except it adds elements to the beginning of the array instead of the end.

var array = [1, 2, 3, 4];
    array.unshift(0);

console.log(array ); // [0, 1, 2, 3, 4]