如何处理 angular 数据表中找不到的记录
How to handle no records found in angular datatables
我正在我的应用程序中使用 angular-datatables
。我不知道如何处理 ajax source returns 空数组。我期待显示一些消息以指示 "No Records found".
$scope.dtOptions = DTOptionsBuilder
.newOptions()
.withOption('ajax', {
dataSrc: 'data',
url: 'api_url',
type: 'GET'
})
.withPaginationType('full_numbers');
$scope.dtColumns = [
DTColumnBuilder.newColumn('id').withTitle('ID'),
DTColumnBuilder.newColumn('firstName').withTitle('First name'),
DTColumnBuilder.newColumn('lastName').withTitle('Last name').notVisible()
];
我的Ajax回复如下
{"status":false,"message":"No data were found","data":[]}
那么如何处理呢?
提供包含所需消息的 language
结构。您要查找的密钥称为 zeroRecords
。小例子:
$scope.language = {
"zeroRecords": "No records found",
}
$scope.dtOptions = DTOptionsBuilder.newOptions()
.withOption('ajax', {
dataSrc: 'data',
url: 'api_url',
type: 'GET'
})
.withPaginationType('full_numbers')
.withOption('language', $scope.language)
演示 -> http://plnkr.co/edit/teJbmQA3wEnzvKEi63IL?p=preview
要捕获 404,只需设置一个错误处理程序即可:
$scope.dtOptions = DTOptionsBuilder.newOptions()
.withOption('ajax', {
dataSrc: 'data',
url: 'api_url',
type: 'GET',
error : function(xhr, ajaxOptions, thrownError){
if (xhr.status==404) {
//no specific action needed
}
}
})
这样您就可以避免丑陋的 dataTables 警告提示框告诉用户出现了 ajax 错误。 zeroRecords
消息仍将显示。
我正在我的应用程序中使用 angular-datatables
。我不知道如何处理 ajax source returns 空数组。我期待显示一些消息以指示 "No Records found".
$scope.dtOptions = DTOptionsBuilder
.newOptions()
.withOption('ajax', {
dataSrc: 'data',
url: 'api_url',
type: 'GET'
})
.withPaginationType('full_numbers');
$scope.dtColumns = [
DTColumnBuilder.newColumn('id').withTitle('ID'),
DTColumnBuilder.newColumn('firstName').withTitle('First name'),
DTColumnBuilder.newColumn('lastName').withTitle('Last name').notVisible()
];
我的Ajax回复如下
{"status":false,"message":"No data were found","data":[]}
那么如何处理呢?
提供包含所需消息的 language
结构。您要查找的密钥称为 zeroRecords
。小例子:
$scope.language = {
"zeroRecords": "No records found",
}
$scope.dtOptions = DTOptionsBuilder.newOptions()
.withOption('ajax', {
dataSrc: 'data',
url: 'api_url',
type: 'GET'
})
.withPaginationType('full_numbers')
.withOption('language', $scope.language)
演示 -> http://plnkr.co/edit/teJbmQA3wEnzvKEi63IL?p=preview
要捕获 404,只需设置一个错误处理程序即可:
$scope.dtOptions = DTOptionsBuilder.newOptions()
.withOption('ajax', {
dataSrc: 'data',
url: 'api_url',
type: 'GET',
error : function(xhr, ajaxOptions, thrownError){
if (xhr.status==404) {
//no specific action needed
}
}
})
这样您就可以避免丑陋的 dataTables 警告提示框告诉用户出现了 ajax 错误。 zeroRecords
消息仍将显示。