datatable cant programatically select row

随声附和 提交于 2020-08-11 00:35:35

问题


I have a datatable with a working system to select rows, if you click anywhere in the row (not just the checkbox), it will select the row (greying it out) and check the box, it also tracks the number of selected rows in the bottom info text.

I'm trying to get the first column header 'select all' checkbox to correctly select all rows, this function detects when the select all button is pressed:

        //select all
        $('body').on('click', '#productGapsSelectAll', function () {
            var allPages = myProductGapsTable.rows().nodes();
            console.log("allPages.length = ", allPages.length, ", allPages = ", allPages)
            
            myProductGapsTable.rows().every(function(rowIdx, tableLoop, rowLoop){
                var node=this.node();
                console.log(`${rowIdx} selected = ${$(node).hasClass('selected')}`);
                $(node).toggleClass('selected');
                //$(node).click()
                //$(node).select();
            });
}

When I use $(node).toggleClass('selected') it only greys out the box, and doesnt check the checkbox,

$(node).click() and $(node).select(); dont check the box or grey the row. Is there some way using $(this) that I can replicate the action of clicking on the row to select it?

EDIT

I can access the checkbox via Node, although no defining ID

edit2; tried getting checkbox value from node but there is no 'checked' string inside the input element

来源:https://stackoverflow.com/questions/62670339/datatable-cant-programatically-select-row

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!