vincentks
vincentks

Reputation: 694

AG-Grid + React - ignore grid sort when adding new row

In an app using AG-Grid Enterprise, React and Redux, I would like to programmatically add a new row to a grid that has sorting enabled. Is is possible to ignore grid sorting and insert this new row in a specific grid position?

To clarify this scenario, I forked the Simple Immutable Store Plnkr available at AG-Grid's website and created a new one here.

In the original Plnkr, button Append will add items to the end of the list. In the forked version, due to column Price ascending sort and due to the fact that new items do not have a price defined anymore, all appended items will show up in the first positions of the grid.

My understanding is that this happens because in the last line from the snippet below (this.gridApi.setRowData), AG-Grid will add new rows and trigger sort, filters, etc.

addFiveItems(append) {
    var newStore = immutableStore.slice();
    for (var i = 0; i < 5; i++) {
      var newItem = createItem(append);
      if (append) {
        newStore.push(newItem);
      } else {
        newStore.splice(0, 0, newItem);
      }
    }
    immutableStore = newStore;
    this.gridApi.setRowData(immutableStore);
  }

With that in mind, is there any AG-Grid API that will allow items to be added in specific grid positions while sort is activated? The goal is to keep Append button original behaviour: append items to the end of the grid, even if sort is defined in this AG-Grid Enterprise, React and Redux scenario.

Upvotes: 0

Views: 1465

Answers (1)

vincentks
vincentks

Reputation: 694

Turns out that from AG-Grid 17+, a new callback, called postSort is available (see https://www.ag-grid.com/javascript-grid-sorting/#post-sort).

As detailed in the documentation above, this callback may be used to tweak row order even after sort is applied.

Upvotes: 1

Related Questions