How to maintain selection on column filter

0
Hello,I am using DataGrid2 with a text filter for a column, and I have enabled multiple row selection. When I select any row and enter details in the column, the selection is lost due to the refresh of DataGrid2. I would like to maintain the row selection after applying or removing the filter. How can I achieve this in a simple way?
asked
2 answers
1

When using a text filter in DataGrid2, the grid refreshes on every change. Since the selection is kept as a UI state, it gets reset during this refresh, which is why multi-row selection is lost when a filter is applied. The simplest way to preserve the selection is not to rely on DataGrid2 itself, but to store the selected rows in a separate helper/selection entity. You update this helper in the selection change event, and when the grid refreshes due to filtering, you restore the selection from this stored list. Because DataGrid2 does not provide a built-in option to automatically keep the selection after a refresh, this “store externally and reapply after refresh” approach is the most stable solution. If you run into any issues while implementing this, feel free to share screenshots and I’ll try to help.


answered
1

hi,


This is expected behavior in DataGrid2.

When you apply or change a column filter, DataGrid2 refreshes its data source, and during that refresh the grid loses its internal selection state. Currently, DataGrid2 does not automatically preserve row selection across filtering.

Recommended (simple & safe) approach

You need to manage the selection yourself:

  1. Store the selected object IDs (or references) in a helper entity or page variable when selection changes.
  2. After the grid refreshes (filter applied/removed), reselect the rows by:
    • Binding selection to that stored list, or
    • Using the grid’s selection datasource pattern (if applicable).

Important note

There is no built-in setting in DataGrid2 to keep selections when filters change. This is a current limitation of the widget.


answered