Custom Button to Hide Rows based on a value

Custom Button to Hide Rows based on a value

silkspinsilkspin Posts: 150Questions: 33Answers: 5

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.

https://live.datatables.net/yuqomafo/1/edit

This question has accepted answers - jump to:

Answers

  • kthorngrenkthorngren Posts: 20,532Questions: 26Answers: 4,815

    You will need a range search similar to this example.

    Kevin

  • silkspinsilkspin Posts: 150Questions: 33Answers: 5

    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?

  • kthorngrenkthorngren Posts: 20,532Questions: 26Answers: 4,815
    Answer ✓

    I updated your example:
    https://live.datatables.net/wixikomo/1/edit

    Kevin

  • silkspinsilkspin Posts: 150Questions: 33Answers: 5

    Thank you so much @kthorngren. That is exactly what I was aiming for, but without any success!

  • allanallan Posts: 62,188Questions: 1Answers: 10,199 Site admin
    Answer ✓

    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

  • silkspinsilkspin Posts: 150Questions: 33Answers: 5

    Thanks to both of you, this works great! I was trying much more complicated methods to achieve a toggle @allan !

  • kthorngrenkthorngren Posts: 20,532Questions: 26Answers: 4,815

    shows how a toggle could be done with a single button

    Missed that requirement :smile:

    Kevin

  • silkspinsilkspin Posts: 150Questions: 33Answers: 5

    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!

  • allanallan Posts: 62,188Questions: 1Answers: 10,199 Site admin

    @allan 's bit was only one line!

    Ah - but what a line ;)

  • silkspinsilkspin Posts: 150Questions: 33Answers: 5

    :)

Sign In or Register to comment.