Datatables toggle feature

Datatables toggle feature

deepak_01deepak_01 Posts: 2Questions: 1Answers: 0

Hi there,
I'm using datatables for displaying rows from a database. Now, I want to allow the user to be able to toggle between displaying active and inactive rows. I'm using bootstrap toggle for this. When the page loads, I see 10 rows per page - these rows can either be "active" or "inactive accounts depending on what the database returns. When the user clicks on "Show active accounts", I'm making all rows with the class"inactive" as hidden. Now, the problem is that this does not then show me 10 active rows, but instead only shows those rows on the table which have class "active". So, for eample if there are 10 row on a page - 6 active accounts and 4 inactive accounts - clicking on show active accounts only shows me 6 active accounts, instead of taking 10 accounts which are active and then displaying them. I understand that the reason this is happening is because I am simply hiding the rows. I tried redrawing the table but that doesn't work. Is there a way I can use a row toggle feature in datatables, or is there a way to integrate bootstrap toggle and datatables? I went through some of the posts which deal with bootstrap toggle but they don't specifically answer my issue.

  • Deepak

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947
    edited November 2017 Answer ✓

    I don't think Datatables is going to know and do anything with the table if you are hiding rows with classes. I presume one of your columns contains information regarding active/inactive. If thats the case then you could use column().search() to search the specific column for the active/inactive values.

    Kevin

  • deepak_01deepak_01 Posts: 2Questions: 1Answers: 0

    Thanks @kthorngren. I need row based toggling, but it appears that datatables doesn't have that.

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947
    edited December 2017

    I need row based toggling

    Do you have data in the row that indicates if the account is active? If so then maybe you could update your toggle events to use column().search() in place of setting the classes.

    Kevin

This discussion has been closed.