Slickgrid 3分组如何删除总计行? [英] Slickgrid 3 grouping how to remove totals row?

查看:97
本文介绍了Slickgrid 3分组如何删除总计行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用多行分组,并将总计放入分组标题中.我不在总计行中使用总计.我看到行被分组,并且总计将是空行.在我的情况下,每个子组之后都有一个空行,最后有一个父级总计的空行.
如何删除这些总计行?谢谢!

I use multi-row grouping and put the totals in the grouping headers. I'm not using the totals in the totals rows. I see the the rows are grouped and where the totals would be there are empty rows. In my case there is an empty row after each of the child grouping and at the end there is an empty row for the parent totals.
How do I remove these totals rows? Thank you!

.cshtml:

  <div id="gridList" class="grid" style="width: 100%; height: 500px"></div>

.js

$(function() {
    var columns = [
    {
        id: "isExcluded",
        name: "Exclude",
        field: "isExcluded" /*, width: 120*/,
        formatter: Slick.Formatters.Checkmark,
        editor: Slick.Editors.Checkbox, sortable: true
    },
    {
        id: "symbol",
        name: "Symbol",
        field: "symbol",
        sortable: true /*, width: 120*/
    },
    {
        id: "price",
        name: "Price",
        field: "price",
        sortable: true
        //, groupTotalsFormatter: sumTotalsFormatter 
    },
    {
        id: "parent_name",
        name: "Parent Name",
        field: "parent_name",
        sortable: true /*, width: 120*/
    },

    {
        id: "description",
        name: "Description",
        field: "description",
        sortable: true,
        width: 120,
        editor: Slick.Editors.Text,
    },
    { id: "cancel_ind", 
      name: "Canceled", 
      field: "cancel_ind", 
      sortable: true, width: 80 }
];

function requiredFieldValidator(value) {
    if (value == null || value == undefined || !value.length) {
        return { valid: false, msg: "This is a required field" };
    } else {
        return { valid: true, msg: null };
    }
};

var options = {
    editable: true,
    enableAddRow: true,
    enableCellNavigation: true,
    asyncEditorLoading: false,
    autoEdit: true,
    enableExpandCollapse: true,
    rowHeight: 25
};

var sortcol = "parent_name";
var sortdir = 1;
var grid;
var data = [];
var groupItemMetadataProviderTrades = new Slick.Data.GroupItemMetadataProvider();
var dataView = new Slick.Data.DataView({ groupItemMetadataProvider:      groupItemMetadataProviderTrades });

dataView.onRowCountChanged.subscribe(function (e, args) {
    grid.updateRowCount();
    grid.render();
});

dataView.onRowsChanged.subscribe(function (e, args) {
    grid.invalidateRows(args.rows);
    grid.render();
});

function groupByParentAndSymbol() {
    dataViewTrades.setGrouping([
        {
            getter: "parent_name",
            formatter: function(g) {
                return "Parent:  " + g.value + "  <span style='color:green'>(" + g.count + " items)  Total: " + g.totals.sum.price + "</span>";
            },
            aggregators: [
                new Slick.Data.Aggregators.Sum("price")
            ],
            aggregateCollapsed: true
            ,lazyTotalsCalculation: true
        },
    {
        getter: "symbol",
        formatter: function(g) {
            return "Symbol:  " + g.value + "  <span style='color:green'>(" + g.count + " items)   Total: " + g.totals.sum.price + "</span>";
        },
        aggregators: [
            new Slick.Data.Aggregators.Sum("price")
        ],
        collapsed: true
        ,lazyTotalsCalculation: true
    }]);
};

grid = new Slick.Grid("#gridList", dataView, columns, options);
grid.registerPlugin(groupItemMetadataProviderTrades);
grid.setSelectionModel(new Slick.RowSelectionModel());

..... /*sorting support etc*/

 // use instead of the default formatter <---  removed not used.
 function sumTotalsFormatter(totals, columnDef) {
    var val = totals.sum && totals.sum[columnDef.field];
    //if (val != null) {
    //    return "total: " + ((Math.round(parseFloat(val) * 100) / 100));
    //}
    return "";
 }

// will be called on a button click (I didn't include the code as irrelevant)
var getDataList = function () {
    $.getJSON('/Home/GetData/', function (json) {
        data = json;
        dataView.beginUpdate();
        dataView.setItems(data);
        groupByParentAndSymbol();
        dataView.endUpdate();
        dataView.syncGridSelection(grid, true);
    });
 };

  getDataList();

});

推荐答案

在数据视图中添加displayTOtalsRow:false解决了我的问题-现在不显示总行数.

Adding displayTOtalsRow: false to the dataview solved my problem - the total rows are not shown now.

 var dataView = new Slick.Data.DataView({ groupItemMetadataProvider: groupItemMetadataProviderTrades, displayTotalsRow: false });

这篇关于Slickgrid 3分组如何删除总计行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆