Clicking on column toggles boolean value

Clicking on column toggles boolean value

jsmith3jsmith3 Posts: 19Questions: 4Answers: 0

Hello

I have a table currently with 5 columns one of which is a boolean value,
I was trying to implement a solution where the user clicks on the column
and that row column 5 would toggle from True to False or False to True

I could find a way to get the data but not update or set the data and have the table refresh with the correct data
eg.

var data = table.row('.selected').data();
alert(data[5]);

I found that if i set the data value manually with say table.row('.selected').data()[0][5] = "False"
then run table.draw() it does not update

What's the best way to do this?

Thanks

Answers

  • kthorngrenkthorngren Posts: 20,269Questions: 26Answers: 4,765

    The docs for row().data() show that you need to pass the updated row data as a parameter. You will need something like this:

    var row = table.row('.selected');
    var data = row.data();
    data[5] = "False";
    row.data( data ).draw();
    

    Kevin

  • jsmith3jsmith3 Posts: 19Questions: 4Answers: 0

    Thank you it worked perfectly

  • jsmith3jsmith3 Posts: 19Questions: 4Answers: 0
    edited February 2020

    I have added a button where I can select multiple rows and click on the button,

    Hoping that it would set each of the rows to say "False"
    I tried var row = table.rows('.selected').data() using var data = row[count]

    Seems to work fine for getting the data via alert() but setting the data it doesn't

    Any ideas?

  • kthorngrenkthorngren Posts: 20,269Questions: 26Answers: 4,765

    To loop through multiple rows use rows().every(). Inside the loop you can get and set the data for each row as above.

    Kevin

This discussion has been closed.