如何更改Kendo UI中网格页面大小的默认值?

MSH*_*MSH 2 telerik kendo-ui

我是Kendo UI的新手.我有我的代码如下.

@(Html.Kendo().Grid<ETS.Model.CompanyList>()
    .Name("grid")
    .Columns(columns =>
    {
        columns.Bound(c => c.CompanyID).Title("Name").Template(@<text>@Html.ActionLink(@item.Name, "Company", "Companies", new { @id = @item.CompanyID }, new { @style = "color:black; text-decoration: none;" })</text>);
        columns.Bound(p => p.City).Title("Billing City");
        columns.Bound(p => p.SalesRep).Title("Sales Rep");
        columns.Bound(p => p.Phone).Title("Company Name");
    })
    .Pageable(pageable => pageable
         .PageSizes(true)
         .ButtonCount(5)
         .Refresh(true)
    )
    .Sortable()                       
    .HtmlAttributes(new { style = "height: auto;" })
    .BindTo(Model.Companies)
)
Run Code Online (Sandbox Code Playgroud)

默认情况下,网格上显示5个项目.有什么办法可以将默认值更改为20吗?

Rio*_*ams 10

一般来说,你会在使用设置PageSize()功能在您DataSource:

@(Html.Kendo().Grid<Product>()
    .Name("grid")
    .DataSource(dataSource => dataSource
        .Ajax() 
        .Read(read => read.Action("Products_Read", "Home"))
        .PageSize(20)
    )
)
Run Code Online (Sandbox Code Playgroud)

或者您可以尝试将可用限制为PageSizes()20:

.Pageable(pageable => pageable.PageSizes(new int[] {20}) ...)
Run Code Online (Sandbox Code Playgroud)

此外,它可以通过Javascript API设置:

var grid = $("#grid").data("kendoGrid");
grid.dataSource.pageSize(20);
grid.refresh();
Run Code Online (Sandbox Code Playgroud)

  • 您是否尝试过显式设置DataSource并使用`.DataSource(ds => ds.Server().PageSize(20))`来查看是否有所不同? (2认同)