我编写了一个java脚本来检查jquery数据表中选定行的数量。但计数不起作用。任何人都可以帮助识别我所犯的错误。
我可能是愚蠢的请原谅并帮助我。
var table = $("#jobsTable").dataTable();
$('#jobsTable tbody').on( 'click', 'tr', function () {
$(this).toggleClass('selected');
alert( table.rows('.selected').data().length +' row(s) selected' );
});
$('#batchAction').click( function () {
alert("button is clicked");
alert( table.rows('.selected').data().length +' row(s) selected' );
var selectedRows = table.rows('.selected').data().length ;
if( selectedRows === 0){
alert("Zero rows selected. Please select jobs to proceed with bulk Operation");
alert( table.rows('.selected').data().length +' row(s) selected' );
}
});
答案 0 :(得分:3)
为什么不呢?
XMLHttpRequest cannot load ..... No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://localhost:8443' is therefore not allowed access.
它必须正常工作。如果不是 - 请给我打电话。
答案 1 :(得分:1)
我认为
alert( table.rows('.selected').data().length +' row(s) selected' );
应该是
alert( table.rows('.selected').length +' row(s) selected' );
该选择器将返回类"选择"
的行数答案 2 :(得分:0)
这是一种直接,简单的方法。使用DT的 count()功能。
var table = $('#example').DataTable();
if ( ! table.data().count() ) {
alert( 'Empty table' );
}
这来自数据表网站本身的一个示例,位于https://datatables.net/reference/api/count()