简体   繁体   中英

Is it possible to override columnDefs order in ag-grid angularjs?

Is it possible to set columnDefs Index value in ag-grid angularjs?

Based on the user while loading time I need to change the order of col.

For some users I need to show the grid data in this order.

In Grid Col1: Model, Col2: Rate, Col3: Price **参考图像**

For some users I need to show the grid data in this order.

In Grid Col1: Price, Col2: Rate, Col3: Model

在此输入图像描述

replace this function in ag-grid.js

   ColumnController.prototype.extractRowGroupColumns = function () {
            var _this = this;
            this.rowGroupColumns = [];
            // pull out the columns
            this.allColumns.sort(function(a, b){
             return a.colDef.seqNo-b.colDef.seqNo
            })

            this.allColumns.forEach(function (column) {

                if (typeof column.getColDef().rowGroupIndex === 'number') {
                    _this.rowGroupColumns.push(column);
                }

            });
            // then sort them
            this.rowGroupColumns.sort(function (colA, colB) {
                return colA.getColDef().rowGroupIndex - colB.getColDef().rowGroupIndex;
            });
        };

In header data add one more column called seqNo like

   $scope.gridheaders = [
                    {headerName: "ID", field: "ID", seqNo:0},
                    {headerName: "Patient Name", field: "PatientName", seqNo:1},
                    {headerName: "Gender", field: "Gender", seqNo:3},
                    {headerName: "Age", field: "Age", seqNo:2},
                    {headerName: "Phone Number", field: "mobileNumber", seqNo:4}
                ];

Then dynamically set seqno based on user...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM