1

我有一个函数可以计算特定列的摘要并将其加载到网格的页脚中。这是代码..

$(function () {
            var gridData = null;
            var nn = null;

            grid = $("#gridId"),
            calculateTotal = function () {
                var gridData = grid.jqGrid('getGridParam', 'data'),
                i = 0, totalAmount = 0, totalduration = 0;

                for (; i < gridData.length; i++) {
                    var rowData = gridData[i];
                    totalAmount += Number(rowData.price);
                    totalduration += Number(rowData.duration);
                }
                grid.jqGrid('footerData', 'set', { name: "TOTAL", duration: totalduration, price: totalAmount });
            };
        });

现在我在这里调用这个摘要函数......

$.ajax({
            url: 'Default.aspx/MyMethod',
            dataType: 'json',
            contentType: "application/json; charset=utf-8",
            type: 'POST',
            success: function (ReportDataNew, textStatus, XMLHttpRequest) {
                //debugger;
                gridData = JSON.parse(ReportDataNew.d);
                console.log(gridData);
                //alert(gridData.length);

                $("#gridId").jqGrid({
                    data: gridData,
                    datatype: "local",
                    height: '100%',
                    autowidth: true,
                    ignoreCase: true,
                    rowNum: 50,
                    rowList: [50, 100, 200],
                    colNames: ['UserName',  'Duration', 'Destination', 'Price'],
                    colModel: [
                            { name: 'username', index: 'username', width: 100, sortable: true, align: 'center' },
                            { name: 'duration', index: 'duration', width: 100, sortable: true, align: 'center' },
                            { name: 'destination', index: 'destination', width: 100, sortable: true, align: 'center' },
                            { name: 'price', index: 'price', width: 100, sortable: true, align: 'center', formatter: 'currency' }

                        ],
                    pager: '#gridpager',
                    viewrecords: true,
                    toppager: true,
                    loadtext: 'Loading...',
                    footerrow: true,
                    userDataOnFooter: true,
                    loadComplete: function () {
                        calculateTotal();
                    }


                });

但是在从过滤器工具栏过滤记录时,页脚行的汇总值保持不变......我需要在从过滤器工具栏过滤或搜索后更新页脚的汇总值......

任何帮助将不胜感激/。提前谢谢..

4

1 回答 1

0

您用于grid.jqGrid('getGridParam', 'data')计算页脚行(摘要行)的值。如果您需要访问独立于所用过滤器的所有页面的所有本地数据,这很实用。如果您需要从当前显示的数据页面(并应用过滤器)计算摘要,您应该使用grid.jqGrid('getRowData')

于 2013-04-03T09:48:20.803 回答