Add class by column value

Add class by column value

glimpsed_chaosglimpsed_chaos Posts: 113Questions: 22Answers: 4
edited April 2019 in Free community support

I have a data table that gets updated data (not through ajax). I need to retain a row if a user has it selected so I can add that class back to the same row if it has a matching value.

All of this works without issue.

What I can't figure out is rather than this, which tries to qualify anything in the table:

$("#team_incidents_table tbody tr:contains(" + thisID + ")").addClass('selected');

How can I add a class just based on it's column? If I try this I get "addClass" is not a function.

incidents_table.rows().data()[0]['incidentID'].addClass('selected');

Provided for clarity:

    //Data comes in from SignalR method from server to client
    chat.client.incidentsTable = function (incidentsTableData) {
        var incidents_table = $('#team_incidents_table').DataTable();
        var select_flag = 0;

       //This gets the value from the "IncidentID" column of the selected row
        if (incidents_table.rows().data().length > 0) {
            if (incidents_table.rows('.selected').any()) {
                var thisID = incidents_table.rows('.selected').data()[0]['incidentID'];
                select_flag = 1;
                incident_selection = thisID;
            }
        }
       
       //This sets my new data, clears the table, draws table and rebuilds the searchPanes
        var data = JSON.parse(incidentsTableData);
        var incidents_table = $('#team_incidents_table').DataTable().clear();
        incidents_table.rows.add(data).draw();
        incidents_table.searchPanes.rebuild();

       //This checks the flag to know it should add a class back to the previously selected item
        if (select_flag == 1) {
           //THIS PART WORKS FINE - But if the thisID value is in another row in a notes field it would also gain that class
            $("#team_incidents_table tbody tr:contains(" + thisID + ")").addClass('selected');

           //DOES NOT WORK - because addClass is not a function
            incidents_table.rows().data()[0]['incidentID'].addClass('selected');
        }

    };

This question has an accepted answers - jump to answer

Answers

This discussion has been closed.