How can I get the rows by data

How can I get the rows by data

rusumatrusumat Posts: 10Questions: 5Answers: 1
edited July 2018 in Free community support

I want to reach the rows(tr) to change the style.
Follow the code;

function ignoreListControl(ignore) {
            var dataarray = $datatable.rows().data().toArray();
            for (var i = 0; i < length; i++) {
                var x = ignoreCustomerList[i];
                var data = dataArray.find(function (element) {
                    return element.CustomerId == x.CustomerId && element.XXId== x.XXId;
                });
                if (!VariableValidate(data)) {
                    continue;
                }
                var row = $datatable
                    .row(data)
                    .node();
                var row2 = $(row); console.log(row2.html());
                var $checkbox = row2.find('td:nth-child(1) input[type="checkbox"][data-noapply="true"]');
                passDeleteControlCFRList(row2, $checkbox, ignore);
            }
        }
function passDeleteControlCFRList($tr, $checkbox, ignore) {
            if (ignore == true) {
                $checkbox[0].checked = false;
                $tr.css("background-color", "#ff8862");
                DeletingCFRListControlPoint($tr, true);
            }
            else if (ignore == false) {
                $checkbox[0].checked = true;
                $tr.css("background-color", "#fff");
                DeletingCFRListControlPoint($tr, false);
            }
            else {
                bla bla bla...
            }
        }
function DeletingCFRListControlPoint($tr, checkedvalue) {
            var clickdata = $datatable.row($tr).data();
            var indexof = deletingCFRList.indexOf(clickdata.XXId);
            if (checkedvalue == true) {
                if (indexof < 0) {
                    deletingCFRList.push(clickdata.XXId);
                }
            }
            else {
                if (indexof >= 0) {
                    deletingCFRList.splice(indexof, 1);
                }
            }
        }

console.log output =>(225)<td><input type="checkbox" id="RemoveCheckBox754" data-noapply="true" checked="checked"></td><td>A01</td><td>column value bla bla...</td><td>stuff something</td><td>stuff something.</td><td>130</td>

Why I get the same row(tr) every time? How can reach to tr?

Thanks.

Answers

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    The row-selector that you use with rows() can be used as a function, allowing you to select rows based on the data they contain.

    Allan

This discussion has been closed.