[英]How to get the page of an item of Kendo Grid using ServerOperation
I'm trying to retrieve the page index of a selected object of the grid that is using ServerOperation, but I don't know how would I do that without too much complication.我正在尝试检索使用 ServerOperation 的网格的选定 object 的页面索引,但我不知道如何在没有太多复杂性的情况下做到这一点。
Currently, I'm receiving an Id from the URL ( https://...?ObjectId=12 ) and I will select this item in the grid, but first I have to show the page it is, so I'm trying to get the page number of this row.目前,我从 URL ( https://...?ObjectId=12 ) 收到一个 Id,我将 select 显示这个项目在第一个页面中获取该行的页码。
The problem is that I'm using ServerOperation(true).问题是我正在使用 ServerOperation(true)。 In addition, I'm retrieving the paged list without any filters.
此外,我正在检索没有任何过滤器的分页列表。
function _displayDetailsModal(id, selectRow = true, focusSelected = true) {
$(document).ready(() => {
var url = `${urls.Details}/${id}`;
if (selectRow) {
// GET PAGE OF ITEM THEN
// CHANGE TO PAGE THEN
kendoGrid.selectById(id);
}
if (focusSelected) {
kendoGrid.focusSelected(); // Scrolls to selected row.
}
loadModal(url);
});
}
Is this the kind of thing you are after?这是你所追求的吗?
Dojo: https://dojo.telerik.com/iNEViDIm/2 Dojo: https://dojo.telerik.com/iNEViDIm/2
I have provided a simple input field where you can set the page number and then a button which will change the page to the selected page for you.我提供了一个简单的输入字段,您可以在其中设置页码,然后提供一个按钮,该按钮将为您将页面更改为所选页面。
All I am doing is setting the datasource's page via the page method and then it will go off and make a read to the remote datasource for you and then return that page of data.我所做的只是通过 page 方法设置数据源的页面,然后它将 go 关闭并为您读取远程数据源,然后返回该数据页面。
$('#btnPage').on('click',function(e){
var page = $('#pageNumber').val();
$('#pageLabel').html('Page Selected Is: ' + page);
var ds = $('#grid').data('kendoGrid').dataSource;
ds.page(parseInt(page));
});
If you select a page higher than the last available then it will just show the last page.如果您 select 的页面高于最后可用的页面,那么它将只显示最后一页。
More info can be seen here: https://docs.telerik.com/kendo-ui/api/javascript/data/datasource/methods/page更多信息可以在这里看到: https://docs.telerik.com/kendo-ui/api/javascript/data/datasource/methods/page
If you need any further info let me know:如果您需要任何进一步的信息,请告诉我:
I ended up doing it on the server.我最终在服务器上完成了它。 That is how I did it:
我就是这样做的:
Controller.cs Controller.cs
Instead of sending just the usual ToDataSourceResult, I add two fiels (PageIndex and ObjectId), and send it to the front-end to change the page and select the row.我不是只发送通常的 ToDataSourceResult,而是添加两个字段(PageIndex 和 ObjectId),并将其发送到前端以更改页面和 select 行。
[HttpPost("List")]
public IActionResult List([DataSourceRequest] DataSourceRequest request, RequestActionViewModel requestAction)
{
// Getting the pageIndex of the ObjectId present in requestAction.
var objectIndex = elementList.FindIndex(el => el.Id == requestAction.ObjectId) + 1;
var objectPageIndex = Math.Ceiling((decimal)objectIndex / request.PageSize);
var dataSourceResult = elementList.ToDataSourceResult(request);
return Json(new {
Data = dataSourceResult.Data,
Total = dataSourceResult.Total,
AggregateResults = dataSourceResult.AggregateResults,
Errors = dataSourceResult.Errors,
// Extra fields
PageIndex = objectPageIndex,
ObjectId = requestAction.ObjectId
});
}
index.js index.js
I Get from the server the page and the id of the element, select the change the page of the grid, and select the element.我从服务器获取页面和元素的id,select 更改网格的页面,select 元素。
function onGridRequestEnd(e) {
this.unbind("requestEnd", onGridRequestEnd);
if (e.PageIndex) {
kendoGrid.bind("dataBound", function temp() {
// Custom method.
kendoGrid.selectById(e.ObjectId, e.PageIndex);
// To avoid looping.
kendoGrid.unbind("dataBound", temp);
});
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.