ui-grid icon indicating copy to clipboard operation
ui-grid copied to clipboard

Creating Cell Filters dynamically

Open flex123 opened this issue 11 years ago • 5 comments

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

flex123 avatar Mar 17 '15 15:03 flex123

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.....

PaulL1 avatar Mar 17 '15 21:03 PaulL1

Paul, thank you very much for the suggestion. I will give it a try.

flex123 avatar Mar 17 '15 22:03 flex123

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

flex123 avatar Mar 18 '15 03:03 flex123

OK, closing. Thanks,

PaulL1 avatar Mar 28 '15 22:03 PaulL1

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.

TojikCZ avatar Oct 01 '17 14:10 TojikCZ