angular-datatables
angular-datatables copied to clipboard
dynamic columns with withFnServerData
Hello, I want fill dtColumns and dtOptions with my ajax call result.
$scope.dtOptions = DTOptionsBuilder.fromSource("sample/json")
.withFnServerData(function (sSource, aoData, fnCallback, oSettings) {
oSettings.jqXHR = $.ajax( {
'dataType': 'json',
'type': 'POST',
'url': sSource,
'data': aoData,
'success': function(json){
angular.forEach(json.headers, function(value, key){
$scope.dtColumns.push(DTColumnBuilder.newColumn(value).withTitle(value).withClass("center").withOption("width", "100px"));
});
fnCallback(json.data);
}
});
});
$scope.dtOptions = DTOptionsBuilder.fromSource("sample/json")
.withFnServerData(function (sSource, aoData, fnCallback, oSettings) {
oSettings.jqXHR = $.ajax( {
'dataType': 'json',
'type': 'POST',
'url': sSource,
'data': aoData,
'success': function(json){
angular.forEach(json.headers, function(value, key){
$scope.dtColumns.push(DTColumnBuilder.newColumn(value).withTitle(value).withClass("center").withOption("width", "100px"));
});
$scope.dtOptions.reloadData();
fnCallback(json.data);
}
});
});
$scope.dtColumns = DTColumnBuilder.newColumn('name').withTitle('Status').withClass("center").notSortable().withOption("width", "15%");
According to 2nd Code, Header Column is not reload. Just 1(Status) exist.
How can i set headers and datas with ajax data?
Your code is not completed (where ddtype comes from?). Can you correct them please?
Sorry, I modified wrong part.
It seems you want to change the header dynamically. There is already a bug report #149 about this.
Thank you, I'll try it.
if server return empty result,how can i setting an empty datatable?