gpt4 book ai didi

javascript - 如何手动设置Kendo Grid的总计数?

转载 作者:行者123 更新时间:2023-11-28 08:32:13 26 4
gpt4 key购买 nike

我试图在删除事件上手动设置网格的总计数值。当按下删除按钮时,删除事件被javascript捕获,传递将被删除的值。最后,我想减少网格的总计数。问题是,我能够减少计数,但我不知道如何将新计数设置为网格的数据源作为总值。

   @(Html.Kendo().Grid<Model>() 
.Name("grid")
.Events(e=>e.Remove("customDelete"))

JS

    e.preventDefault();

var grid = $("#grid").data("kendoGrid").dataSource;
var count = grid.total();
alert(count); // actual count

var countNew= grid.total() - 1 //new count after delete ;
alert(countNew);
//... need to set grid's total count as countNew

$('.k-pager-info').html(1 + " - " + countNew+ " of " + countNew+ " items");
var data = e.model["ID"]; // Getting IDvalue of column
...// Deleting process

最佳答案

我同意@PeturSubev,如果您删除该行,它应该自动递减。如果出于某种原因(我无法理解)您需要将其设置为某个值,解决方案是在 schema.model 中实现自定义 total 函数。 。像这样的东西:

var countNew = undefined;
var dataSource = new kendo.data.DataSource({
transport: {
/* transport configuration */
}
schema: {
total: function (d) {
return countNew || d.length;
}
}
});

// Compute newCount with as you want
var countNew = grid.total() - 1 // new count after delete ;

关于javascript - 如何手动设置Kendo Grid的总计数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21702155/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com