在 dataSource.read 之后获取 Kendo Grid 中的记录数 [英] Get record count in Kendo Grid after dataSource.read
本文介绍了在 dataSource.read 之后获取 Kendo Grid 中的记录数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望能够在阅读(刷新)后从我的剑道网格中推送记录数.
I want to be able to push the record count from my Kendo grid after read (refresh).
这是我的剑道网格:
@(Html.Kendo().Grid(Model)
.Name("SearchWindowGrid")
.Columns(columns =>
{
columns.Bound(p => p.SYSTEM_ITEMS_SEGMENT1).Hidden();
})
.ClientRowTemplate(
"<tr>" +
"<td>" +
"<span><b>#: SYSTEM_ITEMS_SEGMENT1#</b></span> <br/>" +
"<span>#: DESCRIPTION# </span>" +
"</td>" +
"</tr>"
)
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("PopulateSearchWindow", "Item").Data("additionalSearchWindowInfo"))
.Events(ev => ev.Error("onErrorSearchWindow"))
)
.Selectable(s => s.Enabled(true).Mode(GridSelectionMode.Single).Type(GridSelectionType.Row))
.Scrollable(s => s.Enabled(true).Height(450))
)
我的控制器操作:
public ActionResult PopulateSearchWindow([DataSourceRequest] DataSourceRequest request, string option, string searchText, string searchDesc)
{
try
{
var derps= _idg.SearchItems(searchText, searchDesc, _adg.OrganizationCode).ToList();
return Json(derps.ToDataSourceResult(request, ModelState));
}
catch (Exception e)
{
ModelState.AddModelError("ExceptionErrors", e.Message);
return Json(new List<Derp>().ToDataSourceResult(request, ModelState));
}
}
这是我的强制数据刷新函数:
function refreshData(){
$("#SearchWindowGrid").data("kendoGrid").dataSource.read();
//TODO: get the total count and push to #countElement
var count = $("#SearchWindowGrid").data("kendoGrid").length; //not sure what to do here
$("#countElement").val(count);
}
我将 TODO 放在 jQuery 函数中的位置,我希望能够获取行数并将该数字推送到页面上的特定元素中.
Where I put my TODO in the jQuery function I want to be able to get the number of rows and push that number into a specific elemnt on my page.
推荐答案
根据API参考这里
dataSource 有一个 total() 函数.因此,理论上您应该能够执行以下操作:
the dataSource has a total() function. So you should be able to do the following, in theory:
function refreshData(){
var grid = $("#SearchWindowGrid").data("kendoGrid");
grid.dataSource.read();
var count = grid.dataSource.total();
$("#countElement").val(count);
}
这篇关于在 dataSource.read 之后获取 Kendo Grid 中的记录数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文