[英]kendo UI Grid MVC initial page
I am using Kendo UI Grid. 我正在使用Kendo UI Grid。 Is there a way to start the grid at a different page than the first page?
有没有办法在与第一页不同的页面上启动网格? i want to set initial page number to '3' every time i open the grid.
我想在每次打开网格时将初始页码设置为“3”。
I would suggest you to set the AutoBind property of the Grid to false and when the document ready event occurs use the page method of the dataSource (which is actually what the pager.page invokes). 我建议你将Grid的AutoBind属性设置为false ,当文件就绪事件发生时,使用dataSource的page方法(实际上是pager.page调用的方法)。
$('#MyGrid').data().kendoGrid.dataSource.page(3);
The Data function which you used is intended for slightly different purposes :) 您使用的数据函数用于略有不同的目的:)
I use an ajax datasource, and I needed to do: 我使用ajax数据源,我需要这样做:
Here is a fragment of my view (I use razor): Notes: In the action I set two values in the ViewBag: 这是我视图的一个片段(我使用剃刀):注意:在动作中我在ViewBag中设置了两个值:
. 。
@{
int initialPage = (int)ViewBag.InitialPage;
int totalPages = (int)ViewBag.Total / 20;
}
@(Html.Kendo().Grid<YourModelClass>
()
.Name("gridMain")
.Columns(columns =>
{
//Todo: Add your columns
})
.Pageable(p => p.Refresh(true).Info(true).Input(true).ButtonCount(6).Numeric(true))
.Sortable()
.Scrollable()
.Filterable()
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
.Read(read => read.Action("YourAction", "YourController"))
.Total(ViewBag.Total) //Set the total record count
)
.AutoBind(false)
)
<script type="text/javascript">
$(function () {
var initialPage = @initialPage;
$('#gridMain').data().kendoGrid.dataSource.page(initialPage);
})
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.