3
votes

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

1
Have you add an order condition on your ag-grid ? - Toothgip

1 Answers

7
votes

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.