Creating Cell Filters dynamically
Thank you very much for the great work!! I have a problem that I'm not sure how to resolve. In my case, my grid's column definitions, data and cell filters are dynamic and they are returned as part of a $http. The grid's column definitions and data work fine but I'm not sure how to create the cell filters dynamically. The following plunkr demonstrates the issue that I'm having. The "gender" field is using a cell filter called "mapGender" and this cellFilter will be returned as part of the $http together with the column definitions and data. Is it even possible to create cell filters in a controller?
http://plnkr.co/edit/FmX8wZfdxLfmB61xamtB?p=preview
That's probably more an angular question than a ui-grid question. I suspect there's a way to do it directly by injecting filterProvider and doing funky angular stuff, but I'm not that good.
However, a bit more clunky but might work, following this example: http://stackoverflow.com/questions/11753321/passing-arguments-to-angularjs-filters
Using that as an example, I modified to this: http://plnkr.co/edit/dwOlDgXk80EMlYEh7KzW?p=preview
It is calling the function that creates the filter, but it doesn't seem to run the filter. So it's sort of most of the way there.....
Paul, thank you very much for the suggestion. I will give it a try.
It seems like I can use add the following to register the $filterProvider and use it in a controller.
app.config(['$filterProvider', function($filterProvider){ app.filter = $filterProvider.register; }]);
I have updated the plunkr with the solution:
http://plnkr.co/edit/FmX8wZfdxLfmB61xamtB?p=preview
OK, closing. Thanks,
There appears to be a (bug), when the filter is added after the ui-grid fully initializes. For example after waiting for some data on which i build those filters. Simple workaround is to set gridOptions again, although i don't exactly know what that does, it appears to fix my issue.