ansible-cmdb
ansible-cmdb copied to clipboard
Invert search query
Would it be possible to get a way to invert the selection on the search query? I haven't been able to figure out how to do this in html_fancy.tpl
, and I'm wondering if I don't need to drill down farther in the JS to find it. Anyways, whether it's with an "invert selection" checkbox or just by using regex in the search, I would very much appreciate a way to display an inverse selection of the search results.
Hi!
Good question. Ansible-cmdb uses the jQuery datatables plugin for it's search. There are various ways in which it can be customized. It looks like it supports regex search by setting the second parameter to the search call: https://datatables.net/reference/api/search()
I'm not sure if it's possible to change the search parameters after instantiation. Ansible-cmdb doesn't create the search functionality itself. Rather, it is automatically created by the Datatables plugin when calling the constructor.
I'll have a look at this when i'm back from vacation next week. I've only got my mobile phone at my disposal right now.
Thanks for the feature request!
Regards
Ferry
Am I correct in understanding that the instantiation happens at lines 700-722 here? Because it looks like lines 734-741 are just dealing with the permalink. If that's the case, then it seems that there are no parenthesis after the search call, which is confusing me quite a bit (I'm a bash/python guy so this is all foreign to me). It seems like in order to specify search parameters, that I should be able to specify this.fnFilter(qp.search, null, true)
and have regex's interpreted. However, that hasn't been working for me so far.
Anyways, I'll keep playing around with it for the time being. Enjoy your holiday!
Yes the instantiation happens on lines 700-722. The search box is automatically created by DataTables and it looks like it's not possible to easily create our own search() instantiation.
I use the fnInitComplete event to automatically perform a search on the table if a search parameter was specified in the URL of the fancy_html page. I do this through fnFilter. It looks someone else tried to do the same thing with a regex: https://datatables.net/forums/discussion/comment/25936/#Comment_25936
Maybe that could be of some help although I haven't tried it yet. :-)
Moreso, I was just trying to get it to work. It seems like I had to add the fourth argument and set it to false: https://stackoverflow.com/questions/36112455/jquery-datatables-fnfilter-doesnt-work-with-regex
And at the moment it works, but only from the URL bar. The dynamic search doesn't respond to regex, but if I change the URL to a regex, it works just fine. I would assume that qp.search
would return the same values for both the URL and the search bar, so I'm not sure why that behavior would be happening, unless it has to do with the fInitComplete.
So I guess that the I'm-not-going-to-rewrite-everything-from-scratch answer to this is twofold
- Teach people the inverse selection regex of
^(?!.*foobar)
- Use the link button that's generated next to the search to place any and all regex's into the URL and reload the page.
There is a distinct possibility of coming up with a button that wraps a search query in ^(?!.*<search query>)
and places that into the URL bar and reloads the page. However, at least for the time being, the above (along with the fnFilter
arguments talked about in the previous posts) allow for a search query to be inverted.
Let me know if there would be any interest in seeing if I can implement a button like this, and I'll do my best to get it to the point of issuing a PR. Also, let me know if you'd like me to do the same thing you did with host_details=0|1
.