jquery数据表零记录
我使用Datatables 1.10进行服务器端过滤,一切正常,但我需要添加一些内容。目前我有这个代码jquery数据表零记录,jquery,datatables,Jquery,Datatables,我使用Datatables 1.10进行服务器端过滤,一切正常,但我需要添加一些内容。目前我有这个代码 $('#myTable').dataTable({ "language": { "zeroRecords": "No records match", } }); 每当数据表在过滤后或数据表中的zeroRecords中没有值时,我需要显示一个标签 编辑 var oTable = $('#transactionHistoryDataTable').data
$('#myTable').dataTable({
"language":
{
"zeroRecords": "No records match",
}
});
每当数据表在过滤后或数据表中的zeroRecords
中没有值时,我需要显示一个标签
编辑
var oTable = $('#transactionHistoryDataTable').dataTable({
"sPaginationType": "full_numbers",
"bServerSide": true,
"sAjaxSource": "api/Sitecore/Account/DataProviderAction",
"bProcessing": true,
"aoColumns": [
{ "sName": "Date", "bSortable": false },
{ "sName": "Name", "bSortable": false },
{ "sName": "Activity", "bSortable": false },
],
"sDom": '<"top">tip',
"fnServerParams": function (aoData, fnCallback) {
aoData.push({ "name": "ActivityParam", "value": $('#activityList').val() });
aoData.push({ "name": "dateFrom", "value": $('#dateFrom').val() });
aoData.push({ "name": "dateTo", "value": $('#dateTo').val() });
},
"language": {
"loadingRecords": "Loading...",
"zeroRecords": "<span class='label label-danger' >You have no activity for the selected Period</span>",
"sEmptyTable": (function (oSettings, json) {
if ($('#transactionHistoryDataTable').find('tbody tr').length <= 1) {
$('#transactionHistoryDataTable').parent().hide();
$('div.filters > a, #tableheader').hide();
$('#message').text('There are no transactions to display.');
}
})
},
"drawCallback": function (settings) {
if (settings._iRecordsTotal === 0)
$('#temp').show();
else
$('#temp').hide()
}
});
var-oTable=$(“#transactionHistoryDataTable”).dataTable({
“sPaginationType”:“完整编号”,
“bServerSide”:正确,
“sAjaxSource”:“api/Sitecore/Account/DataProviderAction”,
“bProcessing”:正确,
“aoColumns”:[
{“sName”:“Date”,“bSortable”:false},
{“sName”:“Name”,“bSortable”:false},
{“sName”:“Activity”,“bSortable”:false},
],
“sDom”:“提示”,
“fnServerParams”:函数(aoData、fnServerParams回调){
push({“name”:“ActivityParam”,“value”:$('#activityList').val()});
push({“name”:“dateFrom”,“value”:$('#dateFrom').val()});
推送({“name”:“dateTo”,“value”:$('#dateTo').val()});
},
“语言”:{
“加载记录”:“加载…”,
“zeroRecords”:“您在所选期间没有活动”,
“sEmptyTable”:(函数(oSettings,json){
if($('#transactionHistoryDataTable').find('tbody tr').length试试这个
HTML
注意:请参见DataTable
函数名中的差异。D
为大写。您的版本支持此大写D
如果您想用小的d
实现这一点,请使用此
方法1
var oTable =$('#myTable').dataTable({
"language":
{
"zeroRecords": "No records match",
},
"drawCallback": function (settings) {
if (settings._iRecordsTotal === 0)
$('#temp').show();
else
$('#temp').hide()
}
});
方法2
$('#myTable').on('draw.dt', function () {
if (oTable.fnSettings()._iRecordsTotal === 0)
$('#temp').show();
else
$('#temp').hide()
});
关于评论,
谢谢。但是如果标签在桌子外面呢
如果你有
<span class='label label-danger' style="display:none;" id="temp">No records found</span>
- 将其放在dataTable()初始化之前
- DataTable()“typecast”只是为了能够使用更简单的API
试试这个:“zeroRecords”:“找不到记录”
。您可以将html添加到zeroRecords
中,谢谢。但是如果标签在表外怎么办?它不起作用。我也不能使用大写字母D,因为其他函数,如fnDraw
和fnFilter
不起作用,大写字母D将不起作用。我还尝试将设置
更改为oSettings
,drawCallback
到fnDrawCallback
和iRecordsTotal
到fnRecordsTotal
它们都不起作用你能提供一把小提琴吗?对我来说,它使用的是小的d
和drawCallback
更新标签的id
。我在代码中使用了temp
。你使用了myLabel
用于html中的标签。在我的代码中添加一个警报,并检查它是否正在执行。这是我得到的最后一个选项。您确定此事件在没有记录的情况下有效吗?因为我尝试了它,并得到了此错误类型错误:数据未定义解决了此问题。我的数据不正确。无论如何,谢谢!
var oTable =$('#myTable').dataTable({
"language":
{
"zeroRecords": "No records match",
},
"drawCallback": function (settings) {
if (settings._iRecordsTotal === 0)
$('#temp').show();
else
$('#temp').hide()
}
});
$('#myTable').on('draw.dt', function () {
if (oTable.fnSettings()._iRecordsTotal === 0)
$('#temp').show();
else
$('#temp').hide()
});
<span class='label label-danger' style="display:none;" id="temp">No records found</span>
$('#transactionHistoryDataTable').on('draw.dt', function() {
if ($(this).DataTable().data().length==0) {
$("#temp").show();
}
})