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

时间:2014-02-11 12:41:46

标签: javascript jquery asp.net-mvc kendo-ui

我试图在删除事件上手动设置网格的总计数值。当按下删除按钮时,删除事件被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

1 个答案:

答案 0 :(得分:0)

我同意@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  ;