Custom Button to Hide Rows based on a value
Custom Button to Hide Rows based on a value
![silkspin](https://secure.gravatar.com/avatar/3812353d2f8c471dc900ba2751f8e881/?default=https%3A%2F%2Fvanillicon.com%2F3812353d2f8c471dc900ba2751f8e881_200.png&rating=g&size=120)
I have created a test to show how I grey out rows where the ages < 50. I would also like a button option that could hide these under 50 rows, but I'm not sure if what I'm doing is the correct approach. The button that filters could be a toggle, but if I wanted to add more buttons for different results later it would be nice to know how to do both. The other button just needs to show all the previously hidden rows at once.
This question has accepted answers - jump to:
Answers
You will need a range search similar to this example.
Kevin
Hi @kthorngren. I had seen that, but the problem I had was I need this to function from buttons so the style matches the ones in my table. I did try adding functions to the action without success. I also assume that I can't use the function createdrow to achieve this that way. I can't find any other examples. If I add my own buttons in the HTML I know I would be able to attach functions easier with jQuery, but then how would I be able to put DT buttons and HTML buttons together?
I updated your example:
https://live.datatables.net/wixikomo/1/edit
Kevin
Thank you so much @kthorngren. That is exactly what I was aiming for, but without any success!
Here is a little update that @silkspin asked for which shows how a toggle could be done with a single button: https://live.datatables.net/wixikomo/4/edit . It just inverts the flag when the button is pressed.
You could also use
this.text(...)
to update the button's text if you wanted to for each toggle state.Allan
Thanks to both of you, this works great! I was trying much more complicated methods to achieve a toggle @allan !
Missed that requirement![:smile: :smile:](https://datatables.net/forums/resources/emoji/smile.png)
Kevin
No problems @kthorngren You did the hard bit! @allan 's bit was only one line!
Still that doesn't say much for my coding skills does it!
Ah - but what a line![;) ;)](https://datatables.net/forums/resources/emoji/wink.png)