As of the moment writing this, comprehensive documentation on constructing the 'filterText' string is still lacking. Through analyzing the ng-grid.js code and making educated guesses, it becomes apparent that 'filterText' holds more power and versatility than what the current documentation implies.
Setting Up an Example
Before delving into the details, let's look at an example setup for a grid within a controller:
$scope.pricing_data = data['records'];
$scope.gridOptions = {
data: 'pricing_data',
columnDefs: [
{ field: 'ticker', displayName: 'Ticker' },
{ field: 'date', displayName: 'Date' },
{ field: 'close', displayName: 'Close' },
{ field: 'volume', displayName: 'Volume' }
],
filterOptions: {filterText: '', useExternalFilter: false},
showFilter: true
};
The 'pricing_data' object can contain JSON data fetched from the backend. A representation of the table might look similar to this:
Initially, the filterText is empty, displaying all records. The filter option allows users to refine what is displayed based on their search criteria.
The filter dropdown can be used to manipulate the 'filterText' variable, or filter criteria can be directly set in the controller code.
Searching Across the Grid
By default, filterText performs a regex search on every cell within the grid. For instance, searching for the character 'a' will display all entries containing 'a' in any cell. This behavior may suffice for some situations, but in cases with a large dataset, filtering by columns is usually more efficient due to the data structure and performance reasons.
Searching by Specific Columns
To search for a specific string or regex within a single column, the filterText format is:
filterText = '<displayName>:<value>'
For example,
In this case, searching for 'Date' followed by a colon ':' and then a partial string will only select records associated with a specific date. This method allows for precise filtering within a designated column.
To expand the search to include multiple options, the syntax is:
filterText = '<displayName>:<value 1>|<value 2>|...'
Each partial value is separated by a pipe '|', enabling multiple search criteria to be specified. This method allows for a more complex search scope.
Searching Across Multiple Columns
Extending the search to include multiple columns involves adding further syntax to the filterText format:
filterText = '<displayName 1>:<val 1>[|<val 2>|..];<displayName 2>:<val a>[|<val b>|..][;..]'
The use of semicolons ';' separates each column's search criteria. This method allows for cross-column searching with specific conditions.
Continuing with the example, a search for specific entries across different columns can be achieved by combining the search terms effectively.
Updates and Known Issues
Updates or edits in the data are seamlessly filtered through the grid, maintaining the search criteria set by the 'filterText'. This ensures that the filter remains persistent even after data updates.
Adressing Known Bug
An issue related to clearing the filterText causing browser performance concerns has been recently addressed. Referring to the ng-grid issues 777 and 848, updates have been made to alleviate this problem, enhancing the overall user experience.
UPDATE
Following the installation of ng-grid 2.0.8, the problem with clearing filters seems to have been resolved, indicating improved functionality.
Future Developments - ng-grid 3.0
Looking ahead, the development of ng-grid 3.0 is underway, aiming to build upon the existing features and possibly enhance performance and capabilities of the filter functionality. Continual improvements are essential to provide users with a robust and efficient data filtering experience.