Change all data within a column.

Change all data within a column.

ChickenMobileChickenMobile Posts: 7Questions: 3Answers: 0

I'm trying to change all data inside a specific column to the same value when a checkbox is checked.

dt.column("column:name").data($(this).is(":checked")) [1]

This code however just grabs the current data of each cell and doesn't set it them to 'true'.
How can set all values in a column?

Answers

  • ChickenMobileChickenMobile Posts: 7Questions: 3Answers: 0

    Ok, so I figured out a way to change all items in a table in a reasonable time (takes around half a second to replace 600 rows).

    1. Get the current state of data inside the table
    2. Loop through the data and change the needed fields
    3. Clear existing data
    4. Insert new data

    Code:

    $("#SelectAll").change(function() {
        var allDatas = dt.data();
        if ($(this).is(":checked")) {
            for (var i = 0; i < allDatas.length; i++) {
                allDatas[i]["Select"] = true;
                allDatas[i]["InputSelect"] = '<input type="checkbox" checked="checked"/>';
            }
        } else {
            for (var i = 0; i < allDatas.length; i++) {
                allDatas[i]["Select"] = false;
                allDatas[i]["InputSelect"] = '<input type="checkbox"/>';
            }
        }
    
        dt.clear().rows.add(allDatas).draw();
    });
    
This discussion has been closed.