简体   繁体   English

ASP.NET MVC中的Kendo UI Grid分页问题

[英]Kendo UI Grid paging issue in ASP.NET MVC

In my Kendo UI Grid, I set the Page Size attribute to three - PageSize(3): 在Kendo UI网格中,将“页面大小”属性设置为三个-PageSize(3):

@(Html.Kendo().Grid<Kendo.Mvc.Examples.Models.Discount>()
    .Name("discountgrid")
    .Columns(c=>
    {
        c.Bound(d => d.Id);
        c.Bound(d => d.Category);
        c.Bound(d => d.Percentage);
        c.Bound(d => d.Merchandise);
        c.Command(cm => { cm.Edit(); cm.Destroy(); });
    })
    .Pageable()
    .ToolBar(toolbar => toolbar.Create())
    .Editable(editable => editable.Mode(GridEditMode.InCell))
    .DataSource(dataSource => dataSource
        .Ajax()
        .PageSize(3)
        .ServerOperation(false)
        .Model(model => model.Id(d => d.Id))
        .Create(update => update.Action("EditingInline_Create", "Grid"))
        .Update(update => update.Action("EditingInline_Update", "Grid"))
        .Destroy(update => update.Action("EditingInline_Destroy", "Grid"))
    )
)

After adding the first three rows, when I insert the 4th record, the first record disappears (as expected) - but I don't see an option to go to the second page (Page 2) in the grid footer. 添加前三行后,当我插入第4条记录时,第一个记录消失(按预期方式)-但在网格页脚中看不到转到第二页(第2页)的选项。

Why is that? 这是为什么? What am I missing? 我想念什么?

我认为您缺少向网格提供READ操作的功能。

You have to specify the Read action on the DataSource and add the RequestEnd event. 您必须在DataSource上指定Read动作并添加RequestEnd事件。 You can place your DataSource read method inside this event. 您可以将DataSource读取方法放在此事件中。 The event type parameter on the RequestEnd event such as "update","create","destroy" can then be used to determine which operation is complete and reload the data on the grid. 然后,可以使用RequestEnd事件中的事件类型参数(例如“ update”,“ create”,“ destroy”)来确定完成了哪个操作并在网格上重新加载数据。

@(Html.Kendo().Grid<Kendo.Mvc.Examples.Models.Discount>()
.Name("discountgrid")
.Columns(c=>
{
    c.Bound(d => d.Id);
    c.Bound(d => d.Category);
    c.Bound(d => d.Percentage);
    c.Bound(d => d.Merchandise);
    c.Command(cm => { cm.Edit(); cm.Destroy(); });
})
.Pageable()
.ToolBar(toolbar => toolbar.Create())
.Editable(editable => editable.Mode(GridEditMode.InCell))
.DataSource(dataSource => dataSource
    .Ajax()
    .PageSize(3)
    .ServerOperation(false)
    .Events(e => { e.RequestEnd("onRequestEnd"); })//onRequestEnd is the javascript fxn
    .Model(model => model.Id(d => d.Id))
    .Read(read => read.Action("EditingInline_Read","Grid"))
    .Create(update => update.Action("EditingInline_Create", "Grid"))
    .Update(update => update.Action("EditingInline_Update", "Grid"))
    .Destroy(update => update.Action("EditingInline_Destroy", "Grid"))
))


<script type="text/javascript">

function onRequestEnd(e) {
    if (e.type === "create" || e.type === "update" || e.type === "destroy") {
        e.sender.read();
    }
}

</script>

If you need further information, please read this link 如果您需要更多信息,请阅读此链接

尝试将Read()操作添加到网格中,并且出于测试目的,可能设置ServerOperation(true)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM