Suresh B
Suresh B

Reputation: 1652

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 **Ref Image**

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

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

enter image description here

Upvotes: 4

Views: 835

Answers (1)

Suresh B
Suresh B

Reputation: 1652

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...

Upvotes: 1

Related Questions