【问题标题】:slickgrid total光滑网格总数
【发布时间】:2013-01-15 21:00:22
【问题描述】:

在 slickgrid 中,我输入了总和。它总结了该列中的所有行(百分比)并且工作正常。 但现在我面临着我只想从活跃百分比中获取总数。活动列是包含 0 或 1 的其他列。

在列定义中:

{id: "percent", name: "Percent", field: "percent", minWidth: 60, sortable: true, groupTotalsFormatter: sumTotalsFormatter, editor: Slick.Editors.Text}

function sumTotalsFormatter(totals, columnDef, id) 
{
  return "Total: " + Math.round(totals.sum[columnDef.field]) + "%";
}

聚合器:

  dataView.setAggregators([
    new Slick.Data.Aggregators.Avg("percent"),
    new Slick.Data.Aggregators.Sum("percent")
  ], false);

我一直在尝试不同的方法,但没有成功(放置一个不显示的第二个字段来仅存储活动数据,搜索如何修改聚合器......等)。有什么想法吗?

【问题讨论】:

  • 请将您的解决方案移到自己的答案中。其他人可能仍会尝试您会发现有用的不同方法!

标签: javascript slickgrid


【解决方案1】:

(在问题编辑中回答。转换为社区 wiki 答案。参见What is the appropriate action when the answer to a question is added to the question itself?

OP 写道:

好吧,我解决了在 Firebug 中的爬行并重新测试了几次。这是我的解决方案:

function sumTotalsFormatter(totals, columnDef) 
{
  var suma      = 0;
  //current group...
  var groupo    = totals.group.value;
  for (var i=0; i<data.length; i++)
  {
    if(data[i].active == '1')
    {
//data[i].us is the one who makes the groups...
        if(groupo == 1 && data[i].us == '1')
        {
            suma += parseInt(data[i].percent);
        }
        else if(groupo == 0 && data[i].us == '0')
        {
            suma += parseInt(data[i].percent);
        }
    }   
  }
  return "Total: " + suma + "%"; 
}

【讨论】:

    猜你喜欢
    • 2011-12-12
    • 1970-01-01
    • 1970-01-01
    • 2013-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-22
    • 2011-12-14
    相关资源
    最近更新 更多