kendo mvc grid ondatabound 查找符合特定条件的总行数
kendo mvc grid ondatabound find total number of row that match a specific criteria
我可以知道如何查找具有符合特定条件的列的记录总数吗?
//例子
@(Html.Kendo().Grid<Kendo.Mvc.Examples.Models.ProductViewModel>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(p => p.ProductName).Title("Product Name");
columns.Bound(p => p.UnitPrice).Title("Unit Price");
columns.Bound(p => p.UnitsInStock).Title("Units In Stock");
})
.Pageable()
.Sortable()
.Selectable(selectable => selectable
.Mode(GridSelectionMode.Multiple)
.Type(GridSelectionType.Cell))
.Events(events => events.DataBound("onDataBound"))
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("Products_Read", "Grid"))
)
)
<script>
function onDataBound(arg) {
**How can i find the total number of records that the Unit Price equal to 10?**
}
</script>
非常感谢。
你可以用$("#grid").data("kendoGrid").dataItems()获取所有的项目。一旦你有了它们,你只需要遍历它们并将匹配的结果添加到计数器。
function onDataBound(arg) {
var count = 0;
$($("#grid").data("kendoGrid").dataItems()).each(function (index, item) {
if (this.UnitPrice== 10)
count++;
});
}
我可以知道如何查找具有符合特定条件的列的记录总数吗?
//例子
@(Html.Kendo().Grid<Kendo.Mvc.Examples.Models.ProductViewModel>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(p => p.ProductName).Title("Product Name");
columns.Bound(p => p.UnitPrice).Title("Unit Price");
columns.Bound(p => p.UnitsInStock).Title("Units In Stock");
})
.Pageable()
.Sortable()
.Selectable(selectable => selectable
.Mode(GridSelectionMode.Multiple)
.Type(GridSelectionType.Cell))
.Events(events => events.DataBound("onDataBound"))
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("Products_Read", "Grid"))
)
)
<script>
function onDataBound(arg) {
**How can i find the total number of records that the Unit Price equal to 10?**
}
</script>
非常感谢。
你可以用$("#grid").data("kendoGrid").dataItems()获取所有的项目。一旦你有了它们,你只需要遍历它们并将匹配的结果添加到计数器。
function onDataBound(arg) {
var count = 0;
$($("#grid").data("kendoGrid").dataItems()).each(function (index, item) {
if (this.UnitPrice== 10)
count++;
});
}