How to add a class after row data has been changed

How to add a class after row data has been changed

KanthKanth Posts: 20Questions: 9Answers: 0

I am trying to add a CSS class to the changed table row once the data has been updated. I want to check to see if the "CheckedOK" column is checked. If it is, add a class. If it isn't, remove the class. Then deselect all the selected rows.
This is what I have:

editor.on('postSubmit', function (e, json, data, action) {
                if (action == 'edit') {
                    var dta = e.currentTarget.s.editData;
                    $.each(Object.keys(data.data), function (idx, value) {
                        if (dta['CheckedOK'][value] == true) {
                            $(data.data[value]).addClass('RowOK');
                        } else {
                            $(data.data[value]).removeClass('RowOK');
                        }
                    });
                }
                dtOrders.rows().deselect();
            });

I sure this isn't correct, but hopefully it is enough to get the idea across. I think when I check the value of CheckedOK I am actually checking the previous value. If so, what should it read to check the current value?

Answers

  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin

    To access the row node (and thus add or remove a class from it) you would need to use dtOrders.row( ... ).node().

    The ... here is going to be a selector for the row. Assuming you are using DT_RowId as the row identifier parameter then you can use:

    let node = dtOrders.row( ‘#’ + value ).node();
    $(node).addClass( ... );
    

    Is CheckedOK just a boolean value in the data source?

    Allan

This discussion has been closed.