2016-04-20 60 views
1

我是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) 
) 

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

回答

4

通常你会在使用PageSize() function设置你的DataSource

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

或者你可以尝试限制可用PageSizes()只是20:

.Pageable(pageable => pageable.PageSizes(new int[] {20}) ...) 

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

var grid = $("#grid").data("kendoGrid"); 
grid.dataSource.pageSize(20); 
grid.refresh(); 
+0

你的答案让我改变页面的值,但它没有将20设置为默认值。该值在框中为20,但只显示5个项目。 – MSH

+0

您是否尝试过明确设置DataSource并使用'.DataSource(ds => ds.Server()。PageSize(20))'来查看这是否有所作为? –

+0

这工作完美。非常感谢!! – MSH