Reputation: 1550
I'm using Angular datatable in Server side processing mode(Ajax) And use Light Column Filter plugin to filter data in each columns.
HTML
<table datatable dt-options="dtOptions" dt-columns="dtColumns"></table>
Datatable config
DTOptionsBuilder.dtOptions = DTOptionsBuilder.fromSource()
.withOption('processing', true)
.withOption('serverSide', true)
.withDataProp('data')
.withPaginationType('full_numbers')
.withOption('ajax', {
url: '/products',
type: 'GET',
headers: {Authorization: 'Bearer ' + $auth.getToken()},
error: function (xhr, error) {
$log.error(error);
},
complete: function (data) {
$log.log('Done');
}
})
.withLightColumnFilter({
'0': {type: 'text'},
'1': {
type: 'select',
values: [
{ value: 1, label: 'Yes'},
{ value: 0, label: 'No'}
]
}
});
create columns
$scope.dtColumns = [
DTColumnBuilder.newColumn('title').withTitle('title').renderWith(function(data) {
return data;
}),
DTColumnBuilder.newColumn('for_sale').withTitle('for sale').renderWith(function(data){
return data; // 0, 1 or true, false
})
]
Filter with type:'text'
is correct and work fine. But filter with type:'select'
is incorrect! In the other words when I select Yes filter is work and data filtered, But when select No result is empty.
I test select value with 0,1
and true,false
. In both ways, option with true or 1 value is correct but option with 0 or false value is incorrect.
In your opinion, where is the problem?
Upvotes: 2
Views: 2021
Reputation: 85518
You define the values as nunbers
values: [
{ value: 1, label: 'Yes'},
{ value: 0, label: 'No'}
]
But you return strings
return data; // 0, 1 or true, false
data will always be a string because the source is JSON. Try set both to strings and return '0'
and '1'
by force :
{ value: '1', label: 'Yes'},
{ value: '0', label: 'No'}
and
return data == '0' || data == 'false' ? '0' : '1'
Upvotes: 1