【发布时间】:2023-03-26 12:00:01
【问题描述】:
给一个这样的简单表格
<table id="exampleTable" class="table hover nowrap">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
</tr>
</thead></table>
另外,使用jQuery Datatable plugin 并使行可选择,例如this example。 Javascript 是这样的:
var exampleTable = $("#exampleTable").DataTable(
{
"bDestroy": true,
"lengthChange": false,
"bPaginate": false
});
$('#exampleTable tbody').on( 'click', 'tr', function () {
if ( $(this).hasClass('selected') ) {
$(this).removeClass('selected');
}
else {
$('#exampleTable tr.selected').removeClass('selected');
$(this).addClass('selected');
}
} );
因此,当表格为空时,它会显示一个可选择的行,内容如下:
表格中没有可用数据
如何检测表为空且不允许选择那种“消息行”?
Here is a fiddle 带有代码。
【问题讨论】:
-
没有数据时要隐藏表格吗?
-
但是当我只有一行时会发生什么? @Murali 不,我想禁用“无数据”行上的选择。
标签: javascript jquery datatables