ag-grid getPinnedBottomRow获取底部合计行对象

ag-grid getPinnedBottomRow获取底部合计行rowNode对象,行对象结构如下。

getPinnedBottomRow方法

 //获取底部合计行对象
 var rowNode=gridOptions.api.getPinnedTopRow(0);
  //debugger;
  var x=JSON.stringify(rowNode.data);
  alert(x);

在线试一试

完整代码

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>ag-grid getPinnedBottomRow例子</title>
    <script src="http://www.itxst.com/package/ag-grid/ag-grid-community.js"></script>
    <link href="http://www.itxst.com/package/ag-grid/styles/ag-grid.css" rel="stylesheet" />
</head>
<body>
   <div style="margin-bottom: 10px;">
        <input type="button" value="获取底部合计行对象" onclick="func1()" />
          
    </div>
    <div id="myGrid" style="width: 100%;height: 300px;" class="ag-theme-balham"></div>
    <script>
//定义表格列
var columnDefs = [
    { headerName: '名称', field: 'name', 'pinned': 'left' },
    { headerName: 'PV', field: 'pv' },
    { headerName: 'IP', field: 'ip' },
];


//行数据
var rowData = [
    { name: 'itxst.com', pv: 100, ip: 10 }
];


//多模拟几行数据出来
for (var i = 1; i < 20; i++) {
    rowData.push({ name: 'NO11-' + i, pv: 100 * i, ip: 222 * i });
}
         
//将列和数据赋给gridOptions
var gridOptions = {
    columnDefs: columnDefs,
    rowData: rowData,
    getRowStyle: function (params) {
        //********************置顶行样式设置*********************
        if (params.node.rowPinned) {
            return { 'font-weight': 'bold', 'color': 'red' };
        }
    },
    onGridReady: function () {
        //表格创建完成后执行的事件 调整表格大小自适应
        gridOptions.api.sizeColumnsToFit(); 
        count();
    },
    defaultColDef: {
        enableRowGroup: true,
        enablePivot: true,
        enableValue: true,
        sortable: true, //开启排序
    },
   pagination: true,  //开启分页(前端分页)
   paginationAutoPageSize: true, //根据网页高度自动分页(前端分页)
};
//在dom加载完成后 初始化agGrid完成
document.addEventListener("DOMContentLoaded", function () {
    var eGridDiv = document.querySelector('#myGrid');
    new agGrid.Grid(eGridDiv, gridOptions);
});
//********************设置置顶并统计每行的汇总数据********************* 
function count() {
    var pvCount = 0;
    var ipCount = 0;
    for (var i = 0; i < rowData.length; i++) {
        pvCount = pvCount + rowData[i].pv;
        ipCount = ipCount + rowData[i].ip;
    }


    var topRows = [
        { name: '合计', pv: pvCount, ip: ipCount }
    ];
    gridOptions.api.setPinnedTopRowData(topRows);
}
  
 //获取底部合计行对象
 function func1() {
  var topRow=gridOptions.api.getPinnedBottomRow(0);
  //debugger;
  var x=JSON.stringify(topRow.data);
  alert(x);
}
    </script>
</body>
</html>