0

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.

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.