Custom filtering
I can't find any examples on how to write custom filters for ng-grid. It's easy to write a custom filter that filters out rows from ng-grid by simply manipulating the data used by ng-grid, but I have a fairly large dataset and don't want to keep an extra copy of the data.
Is it possible to use the gridOptions.useExternalFilter option? I can't find any examples the explains what it does.
Here's a very simple plunk http://plnkr.co/edit/T6qaQX
I think I got it. Trying to pipe my data through an angular filter:
$scope.gridOptions = {
data: 'myData|gridFilter:filterOptions'
}
And this is how to final plunker looks after updating http://embed.plnkr.co/T6qaQX
I've been trying to figure out custom filtering, and your plunkers don't appear to have any filtering in them at all.
Sorry, I've updated the plunk and have stopped working with angular since one month ago. If you do figure it out, please make a blog posts about it. There's a lack of good examples.
I made a quick plunk here: http://plnkr.co/edit/raZXLH
It uses the built-in filterOptions.filterText property to do the filtering. One important thing to note is that if you change the displayName of the column in columnDefs, you MUST use that displayName as the column predicate in your filter text.
So if the displayName of the "name" column is set to "Dude Name", your custom filter text would be: "Dude Name:Nephi".
Thanks for that plunk c0bra, helps a lot to understand the binding.
I am trying to implement a search box, just like the one that is built in (which is enabled by showFilter: true), but I want to be able to put it outside the grid, to customize the user interface. Do you know how to implement this?
@horduringi like this? http://plnkr.co/edit/PHdBhF?p=preview
This is exactly what I need. Thank you so much!
Hey @c0bra , you should put your answer here: http://stackoverflow.com/questions/17977869/how-to-filter-my-data-ng-grid. I also found out that you can do a compound filter like this:
name:n;age:3
That would show the table:
Tiancum 43
Enos 34
@jesslilly thanks for the tip; I've added an answer
c0bra, great example.
for some reason when i tested the filtering i noticed that |, $, ^ is not taking into consideration as other special chars.
Is there any known reason for that?
@ronenme I don't know off the top of my head. Filtering in 2.x can be all sorts of wonky and I wasn't involved in writing it. My personal first step would be to do a lot of googling, which you've probably already done.
@c0bra , thanks for the response.
I will continue with the googling :+1:
Nice example @c0bra , is there any chance I could do the same in 3.x?
Refer #1765, short answer is that it is not currently possible in 3.x.
Thanks for the reference, seems that there is some kind of a workaround, will check it out tomorrow. However, is there a possibility that it will be included in a foreseeable future? @PaulL1
It depends on how far into the future we can forsee. :-) I think having put the thought into #1765 I can see how it can be done, so the actual coding isn't a barrier. But I have quite a few things on my plate, and am potentially starting a new role soon that would reduce my time. So it's not likely that I'll personally do it in the near future. We're always open to new contributors though - and this is something I think someone new to the team could achieve reasonable easily. Check the first timers guide https://github.com/angular-ui/ng-grid/blob/master/FIRST_TIMER.md
I looked at the workaround at #1765 and also the ui-grid source code. It seems that there could be a simpler solution than in #1765 that would allow to reuse the existing filter code. By passing giving external ng-model as colDef value( e.g. externalFilter) which could then be set as the "filter.term". Unfortunately I failed to grasp where is $watch being set for the internal filter inputs. Are you familiar with this side of the code and maybe could point me to the right direction @PaulL1 ?
You could do this if you're happy for the filter to run against only a single column. The filter logic in 3.0 is column by column.
Is there way to filter {blank} data? I've tried using null, empty but wasn't successful.