问题
For a new project we are using SlickGrid which is a very neat tool for displaying grid data. We are trying to implement a search box above the grid which filter the content of the grid. We're using a DataView with the grid and we can use the functions 'setFilter' and 'setFilterArgs' to implement the filter on the DataView.
We also use custom formatters to format the content of the cells for some fields. For example the country is a country code in our data object (for example 'NL') but we use a formatter in the grid column definitions to display it as the translated value 'Netherlands'. Also dates are formatted this way.
The problem is: We can only filter on the content in the data object because it is accessible from the DataView, but we need to filter on the formatted content which is presented in the cells by the grid. Is there any way to get this done in a fast and good way ?
回答1:
CPU efficient way: in your formatter function, assign, just before your return statement:
dataContext.countryName = myFullCountryName;
This will add a new property to the item/row. Then when you're sorting on the country
column, simply reference the countryName instead.
The memory efficient way would be to simply pass each country value through your formatter function before doing the comparison in your sorting function.
来源:https://stackoverflow.com/questions/13585994/slickgrid-filter-on-formatted-cell-content