在编辑时刷新Kendo UI MVC网格的ClientFooterTemplate

时间:2014-02-25 14:47:38

标签: c# asp.net kendo-ui kendo-grid kendo-asp.net-mvc

我在ajax模式下使用Kendo UI网格,并且有一个ClientFooterTemplate,其总和为列的总和。这一切都运行良好,但如果我创建/更新或删除记录,ClientFooterTemplate不会更新,并且总和值保持不变。

如何更新ClientFooterTemplate,以便在创建/更新或删除后总和值是最新的?

这是我到目前为止所尝试的:

.Events(events =>
{
    events.SaveChanges("SaveChanges");
    events.Remove("Remove");
    events.Save("SaveChanges");
})
<script>
    function SaveChanges(e) {
        Reload(e.sender);
    }
    function Remove(e) {
        Reload(e.sender);
    }
    function Reload(obj) {
        obj.dataSource.read();
    }
</script>

obj.dataSource.read()在实际更新请求之前执行。

3 个答案:

答案 0 :(得分:1)

你需要更新数据源并再次获取,如果你使用聚合总和在你的网格页脚之后javascript将在你每次创建/更新任何行时更新你的页脚总和。

.DataSource(dataSource => dataSource
                        .Ajax()
                        .Aggregates(aggregates =>
                        {
                            aggregates.Add(p => p.WorkOrderDetailsQuantity).Sum();
                            aggregates.Add(p => p.Total).Sum();                         
                        })

.Events(E =&GT; e.Edit( “onEdit”)保存( “的onSave”))


function onSave(e)
        {
            //update the aggregate columns
            var dataSource = this.dataSource;
            e.model.one("change", function () {
                dataSource.one("change", function () {
                    dataSource.aggregates().Total.sum;
                });
                dataSource.fetch();
            });

        }

Reagrds

shaz

答案 1 :(得分:0)

您可能需要对网格的数据源进行刷新。 所以在更新之后你可以像这样刷新它......

 var grid = $("#ProposalGrid").data("kendoGrid");
             grid.dataSource.page(1) // or
             grid.dataSource.read() //if dataSource Read expects a paramater
             grid.dataSource.read( {paramNameAsDefinedInController : value });

答案 2 :(得分:0)

如果您不想重新加载数据,可以随时执行此类操作(有点hacky ......):

首先,对Save事件与SaveChanges事件使用不同的函数,例如:

.Events(events => {
    events.Save("Save");
    events.SaveChanges("SaveChanges");
    events.Remove("Remove")
})

其次,定义JavaScript方法,例如:

function Save(e) {
    if (e.value.Gewgaw) { // replace 'Gewgaw' with your column name
        var footer = $('tr.k-footer-template'),
            idx = 3, // replace 3 with the column index you want to aggregate
            aggregate = $(footer).children('td')[idx]; 

        // I had to delay the stuff in this function to get it to load properly
        setTimeout(function () { 
            var sum = 0;

            $('tr[role=row][data-uid]').each(function(i, e) {
                var $cell = $($(e).children()[idx]);

                /* do any necessary manipulations before this 
                   if your cell is formatted */
                var cellAmount = parseFloat($cell.text()); 

                sum += cellAmount;
            });

            /* do any necessary formatting to sum before this 
               if your cell is formatted */
            $(aggregate).text(sum); 
        }, 50); 
    }
}

如果您执行该操作并删除/添加适当的格式,则每次编辑相应的单元格时都应更新聚合。

相关问题