using aggrid and a datasource, I want to select the first record after performing an…
- User
using aggrid and a datasource, I want to select the first record after performing an onsort operation, but the sort operation appears to be occurring before the data is returned from the api. How can I accoplish this?
- Assistant
If the sort operation is occurring before the data is returned from the API, it means that the API is returning the data already sorted. In this case, you can still use ag-Grid's
onSortChangedevent to capture the sorting and select the first record.Here's how you can accomplish this:
- In your
onGridReadyevent handler, set up your data source to retrieve data from the API:
javascript - In your
- User
junior says he tried this and it doesn't work
- Assistant
If the approach I suggested is not working for Junior, there may be a few things to check:
- Make sure the
onSortChangedevent handler is attached to the grid. This can be done by adding the following to your grid options:
javascriptonSortChanged: onSortChangedWhere
onSortChangedis the name of your event handler function.- Make sure the
getRowsmethod of the data source is returning an unsorted data set. If the data is already sorted before it's returned from the API, ag-Grid will not re-sort it, and theonSortChangedevent will not be triggered. If the data is being returned sorted, you can try adding a random field to the data and sorting on that field to force ag-Grid to re-sort the data. For example:
javascript - Make sure the
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.