首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在编辑时刷新Kendo UI MVC网格的ClientFooterTemplate

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

Stack Overflow用户
提问于 2014-02-25 22:47:38
回答 3查看 5.1K关注 0票数 0

我在ajax模式中使用了Kendo UI网格,并有一个包含列总和的ClientFooterTemplate。这一切都工作得很好,但是如果我创建/更新或删除一条记录,ClientFooterTemplate不会更新,并且sum值保持不变。

如何更新ClientFooterTemplate,使sum值在创建/更新或删除后是最新的?

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

代码语言:javascript
运行
复制
.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()在实际的更新请求之前执行。

EN

回答 3

Stack Overflow用户

发布于 2014-02-26 18:18:16

您需要更新datasource并再次获取,如果您在网格页脚中使用聚合sum,下面的JavaScript将在您每次创建/更新任何行时更新您的页脚sum。

代码语言:javascript
运行
复制
.DataSource(dataSource => dataSource
  .Ajax()
  .Aggregates(aggregates =>
  {
    aggregates.Add(p => p.WorkOrderDetailsQuantity).Sum();
    aggregates.Add(p => p.Total).Sum();                         
  })
.Events(e=>e.Edit("onEdit").Save("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();
  });
}
票数 2
EN

Stack Overflow用户

发布于 2014-02-25 23:12:46

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

代码语言:javascript
运行
复制
 var grid = $("#ProposalGrid").data("kendoGrid");
             grid.dataSource.page(1) // or
             grid.dataSource.read() //if dataSource Read expects a paramater
             grid.dataSource.read( {paramNameAsDefinedInController : value });
票数 0
EN

Stack Overflow用户

发布于 2014-06-20 22:10:51

如果你不想重新加载你的数据,你总是可以这样做(有点老生常谈...):

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

代码语言:javascript
运行
复制
.Events(events => {
    events.Save("Save");
    events.SaveChanges("SaveChanges");
    events.Remove("Remove")
})

第二,定义JavaScript方法,例如:

代码语言: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); 
    }
}

如果您这样做,并删除/添加适当的格式,那么每次编辑相应的单元格时,它都应该更新聚合。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22017631

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档