2
votes

I'm still learning about Angular/ui-grid and have gotten stuck and hoping someone can point me in the right direction. When you set up your grid you can turn on filtering with:

$scope.gridOptions.enableFiltering = true;

Then in the columnDefs when you define your grid you can turn on column filtering with various tests (equal to, contains, exact, less than, etc. ) or make up your own - i.e. you can even define your own boolean function to drive the pass/fail of each row for your desired filtering logic. Here's a typical example:

{
   field: 'phone',
   filter: {
     condition: function(searchTerm, cellValue) {
       var strippedValue = (cellValue + '').replace(/[^\d]/g, '');
       return strippedValue.indexOf(searchTerm) >= 0;
     }
},

But this filtering logic ability all seems to be specific to one column. So what if you have a filtering test that is cross-field (simple example: does field A = field B?) or possibly even cross-row (i.e. I actually have a case where I do complex test across sets of rows to determine which rows should be filtered in/out). Is there a standard method for how to do this sort of more global filtering?

I've gotten close to a solution by saving the include/exclude results of the calculation in a hidden column that is not actually displayed, but I cannot seem to get ui-grid to actually execute the filter function on the hidden column. This raises a related question: how can you force the execution of a filtering operation (because I would like to trigger from a control that is not part of the grid)?

I tried to put together a plunkr of the simpler case (does A = B ?): http://plnkr.co/edit/a0BJZVOGGIyP4Q4hxVob?p=preview

I think if I understood how to make that work, perhaps the answer would also answer (or make moot) the dynamic aspect (how to force the filter operation when needed) of the problem as well.

Thanks for any assistance

2

2 Answers

2
votes

I've added a cross field example today to the tutorials: http://ui-grid.info/docs/#/tutorial/321_singleFilter

The key is that the base filtering works on a column at a time. It starts with all the rows visible, and then sets a row invisible if it doesn't match any of the individual column filters. What you're asking for is more akin to an OR condition, which the filtering doesn't currently support.

What you can do, though, is build a custom rowsProcessor that applies custom filtering, and the tutorial provides an example of that.

0
votes

Try something like this

{
   field: 'phone',
   filter: {
     condition: function(searchTerm, cellValue) {
       var strippedValue = (cellValue + '').replace(/[^\d]/g, '');
       var match1 = strippedValue.indexOf(searchTerm) >= 0;
       var match2 = // some Other condition
       return (match1 || match2); //add additional matches as needed.
     }
},