Kendo grid Insert new record on the last page, last row position

左心房为你撑大大i 提交于 2019-12-05 16:56:32

You should define a custom command in your toolbar as:

toolbar   : [
    {
        name : "my-create",
        text : "Add new record"
    }
],

Then, add an event listener to it, using as selector k-grid- plus the name of the command.

$(".k-grid-my-create", grid.element).on("click", function (e) {
}

Finally we will use the ability of Kendo UI datasource for inserting in a specific point:

var dataSource = grid.dataSource;
var total = dataSource.data().length;
dataSource.insert(total, {});
dataSource.page(dataSource.totalPages());
grid.editRow(grid.tbody.children().last());

Please, realize that we should move to the last page after inserting the row. This should be ok with having columns sorted by date.

Please, check the code here: http://jsfiddle.net/OnaBai/sAVGk/

Check out new kendo setting: createAt

just set it to the 'bottom':

...
createAt: 'bottom',
...

Is there a possibility to prevent Grid sorting only for the case when new row is added?

In add button handler use next code:

        var table = $("#gridId").data("kendoGrid");
        var sorting = table.dataSource.sort();

        if (sorting) {
            table.dataSource.sort(null);
        }
        table.addRow();

Sorting will be removed and new item will be in edit mode.

If it is an MVC Kendo Grid, attach .CreateAt(GridInsertRowPosition.Bottom) attribute. Below is the sample line,

.Editable(e => e.Mode(GridEditMode.InCell).CreateAt(GridInsertRowPosition.Bottom))
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!