Enabling Filtering and Sorting for Unbound Custom Fields in Acumatica Grids
When working with Acumatica customizations, enabling filtering and sorting for unbound custom fields in grids can be a challenge. This article provides a step-by-step guide to achieving this functionality, ensuring the grid behaves as expected while adhering to Acumatica's best practices.
Scenario
A common requirement when extending Acumatica screens is to add unbound custom fields to a grid. For instance, consider a grid with fields like Location ID and Location Name. These fields need to:
- Allow filtering by user input.
- Support sorting in ascending or descending order.
Unbound fields are not stored in the database, which makes enabling these features more complex.
Solution: Leveraging the FieldSelecting Event
The PXFieldSelecting event can dynamically populate unbound fields and allow them to participate in filtering and sorting within the grid.
Implementation Steps
Define the Unbound Field
Ensure the unbound field is defined in the DAC (Data Access Class) using the [PXUIField] attribute:
Handle the PXFieldSelecting Event
Use the PXFieldSelecting event to dynamically assign values to the unbound field:
● Key Point: The FieldSelecting event is invoked whenever the field value needs to be retrieved for display or filtering.
Enable Filtering and Sorting in the Grid
In the customization project, ensure the field is marked as Allow Filter and Allow Sort in the grid properties.
Why FieldSelecting is Better than RowSelected
Using the RowSelected event for grid-related logic is discouraged because it processes each row after retrieval, potentially degrading performance. The PXFieldSelecting event is more efficient, as it only evaluates fields when needed.
Key Takeaways
● Dynamic Calculation: Use PXFieldSelecting to dynamically fetch unbound field values.
● Performance Optimization: Avoid the RowSelected event for grid population to improve performance.
● User Experience: Ensure fields are properly configured in the customization editor for filtering and sorting.
By following these steps, developers can seamlessly add filtering and sorting capabilities to unbound custom fields in Acumatica grids, enhancing both functionality and user experience.