简体   繁体   中英

Ag grid: How to add a row with sorting order

I have been trying an issue like while adding the row into ag grid, it is always adding in bottom of the grid without sort order.

I would like to add the row with sorting order here the example what is happening when I add the row,

Actual results is

4
5
6
1 => Newly added row without sorting.

Expected result is

1 => Newly added row with sorting.
4
5
6

This is the syntax using from Ag-grid.

const addedRow = this.gridOptions.api.updateRowData({ add: [view.data]});
      addedRow.add[0].setSelected(true);

Any expert advice

No sort(Default: Loading the data as per the array order)

8

4

9

1 => Added new Row

Ascending

1 => Added new Row

4

8

9

Descending

9

8

4

1 => Added new Row

You can set the sort order of your grid using the gridApi .

In the onGridReady callback, set the following sort:

onGridReady(params) {
      this.gridApi = params.api;

      var sort = [
          {
            colId: "id",
            sort: "asc"
          }
        ];
        this.gridApi.setSortModel(sort);
    }

Then when you've added your new row, it will be automatically order by the id field in ascending order.

Take a look at this StackBlitz example.

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