How to reinitialize jquery datatable on initComplete event . i have add one ajax call in initComplete and want to replace data of datatable how can i do this is there any one have idea?
如何在initComplete事件上重新初始化jquery数据表。我在initComplete中添加了一个ajax调用,并且想要替换datatable的数据我怎么能这样做有没有人有想法?
Here is my code.
这是我的代码。
$scope.tbOptionsrejectionreport = {
data: [],
bAutoWidth: false,
sAjaxSource: 'api/api.php?type=get_rejectionreport&status=default&managerId='+managerid+'&isAdmin='+Adminuser,
initComplete: function ()
{
$("#rejectionreportlist").click(function(){
$('#example_rejectionreport').DataTable().clear().destroy();
var rejection_date = $("#rejectiondate").val();
$http.post(
'api/api.php?type=get_rejectionreport&rejectiondate='+rejection_date+'&managerId='+managerid+'&isAdmin='+Adminuser,
{
})
.then(function( answer) {
//$("#example_rejectionreport").dataTable().fnDestroy();
$("#example_rejectionreport").dataTable({
data: [],
bAutoWidth: false ,
aoColumns : [
{
sWidth: "1%",
bSortable: true,
mRender: function (data, type, full) {
var tbAction = '';
tbAction += full[0];
return tbAction;
}
},
{
sWidth: "1%",
bSortable: true,
mRender: function (data, type, full) {
var tbAction = '';
tbAction += full[1];
return tbAction;
}
},
{
sWidth: "5%",
bSortable: false,
mRender: function (data, type, full) {
var tbAction = '';
tbAction += full[2];
return tbAction;
}
},
{
sWidth: "3%",
bSortable: false,
mRender: function (data, type, full) {
var tbAction = '';
tbAction += full[3];
return tbAction;
}
},
{
sWidth: "3%",
bSortable: false,
mRender: function (data, type, full) {
var tbAction = '';
tbAction += full[4];
return tbAction;
}
},
{
sWidth: "3%",
bSortable: false,
mRender: function (data, type, full) {
var tbAction = '';
tbAction += full[5];
return tbAction;
}
},
{
sWidth: "3%",
bSortable: false,
mRender: function (data, type, full) {
var tbAction = '';
tbAction += full[6];
return tbAction;
}
},
{
sWidth: "3%",
bSortable: true,
mRender: function (data, type, full) {
var tbAction = '';
tbAction += full[12];
return tbAction;
}
},
],
createdRow: function(row, data, dataIndex) {
$compile(row)($scope)
}
});
/*var table = $("#example_rejectionreport").DataTable();
console.log(answer.data.aaData);
$scope.rejectionlist= answer.data.aaData;*/
});
});
},
aoColumns: [
{
sWidth: "1%",
bSortable: true,
mRender: function (data, type, full) {
var tbAction = '';
tbAction += full[0];
return tbAction;
}
},
{
sWidth: "1%",
bSortable: true,
mRender: function (data, type, full) {
var tbAction = '';
tbAction += full[1];
return tbAction;
}
},
{
sWidth: "5%",
bSortable: false,
mRender: function (data, type, full) {
var tbAction = '';
tbAction += full[2];
return tbAction;
}
},
{
sWidth: "3%",
bSortable: false,
mRender: function (data, type, full) {
var tbAction = '';
tbAction += full[3];
return tbAction;
}
},
{
sWidth: "3%",
bSortable: false,
mRender: function (data, type, full) {
var tbAction = '';
tbAction += full[4];
return tbAction;
}
},
{
sWidth: "3%",
bSortable: false,
mRender: function (data, type, full) {
var tbAction = '';
tbAction += full[5];
return tbAction;
}
},
{
sWidth: "3%",
bSortable: false,
mRender: function (data, type, full) {
var tbAction = '';
tbAction += full[6];
return tbAction;
}
},
{
sWidth: "3%",
bSortable: true,
mRender: function (data, type, full) {
var tbAction = '';
tbAction += full[12];
return tbAction;
}
},
],
createdRow: function(row, data, dataIndex) {
$compile(row)($scope)
}
};
1 个解决方案
#1
0
This is my answer finally i found it
这是我的答案,终于找到了它
var Adminuser = $scope.isAdmin;
var managerid = $scope.userID;
$scope.tbOptionsrejectionreport = {
data: [],
bAutoWidth: false,
sAjaxSource: 'api/api.php?type=get_rejectionreport&status=default&managerId='+managerid+'&isAdmin='+Adminuser,
initComplete: function ()
{
$("#rejectionreportlist").click(function(){
$('#example_rejectionreport').DataTable().clear().destroy();
var rejection_date = $("#rejectiondate").val();
$http.post(
'api/api.php?type=get_rejectionreport&rejectiondate='+rejection_date+'&managerId='+managerid+'&isAdmin='+Adminuser,
{
})
.then(function( answer) {
var data = answer.data.aaData;
var table = $('#example_rejectionreport').DataTable({
destroy: true,
bLengthChange: false,
paging: true
});
$.each(data, function(i, item) {
//console.log("inserting", item);
table.row.add([
item['0'],
item['1'],
item['2'],
item['3'],
item['4'],
item['5'],
item['6'],
item['12'],
]).draw();
});
});
});
},
aoColumns: [
{
sWidth: "1%",
bSortable: true,
mRender: function (data, type, full) {
var tbAction = '';
tbAction += full[0];
return tbAction;
}
},
{
sWidth: "1%",
bSortable: true,
mRender: function (data, type, full) {
var tbAction = '';
tbAction += full[1];
return tbAction;
}
},
{
sWidth: "5%",
bSortable: false,
mRender: function (data, type, full) {
var tbAction = '';
tbAction += full[2];
return tbAction;
}
},
{
sWidth: "3%",
bSortable: false,
mRender: function (data, type, full) {
var tbAction = '';
tbAction += full[3];
return tbAction;
}
},
{
sWidth: "3%",
bSortable: false,
mRender: function (data, type, full) {
var tbAction = '';
tbAction += full[4];
return tbAction;
}
},
{
sWidth: "3%",
bSortable: false,
mRender: function (data, type, full) {
var tbAction = '';
tbAction += full[5];
return tbAction;
}
},
{
sWidth: "3%",
bSortable: false,
mRender: function (data, type, full) {
var tbAction = '';
tbAction += full[6];
return tbAction;
}
},
{
sWidth: "3%",
bSortable: true,
mRender: function (data, type, full) {
var tbAction = '';
tbAction += full[12];
return tbAction;
}
},
],
createdRow: function(row, data, dataIndex) {
$compile(row)($scope)
}
};
#1
0
This is my answer finally i found it
这是我的答案,终于找到了它
var Adminuser = $scope.isAdmin;
var managerid = $scope.userID;
$scope.tbOptionsrejectionreport = {
data: [],
bAutoWidth: false,
sAjaxSource: 'api/api.php?type=get_rejectionreport&status=default&managerId='+managerid+'&isAdmin='+Adminuser,
initComplete: function ()
{
$("#rejectionreportlist").click(function(){
$('#example_rejectionreport').DataTable().clear().destroy();
var rejection_date = $("#rejectiondate").val();
$http.post(
'api/api.php?type=get_rejectionreport&rejectiondate='+rejection_date+'&managerId='+managerid+'&isAdmin='+Adminuser,
{
})
.then(function( answer) {
var data = answer.data.aaData;
var table = $('#example_rejectionreport').DataTable({
destroy: true,
bLengthChange: false,
paging: true
});
$.each(data, function(i, item) {
//console.log("inserting", item);
table.row.add([
item['0'],
item['1'],
item['2'],
item['3'],
item['4'],
item['5'],
item['6'],
item['12'],
]).draw();
});
});
});
},
aoColumns: [
{
sWidth: "1%",
bSortable: true,
mRender: function (data, type, full) {
var tbAction = '';
tbAction += full[0];
return tbAction;
}
},
{
sWidth: "1%",
bSortable: true,
mRender: function (data, type, full) {
var tbAction = '';
tbAction += full[1];
return tbAction;
}
},
{
sWidth: "5%",
bSortable: false,
mRender: function (data, type, full) {
var tbAction = '';
tbAction += full[2];
return tbAction;
}
},
{
sWidth: "3%",
bSortable: false,
mRender: function (data, type, full) {
var tbAction = '';
tbAction += full[3];
return tbAction;
}
},
{
sWidth: "3%",
bSortable: false,
mRender: function (data, type, full) {
var tbAction = '';
tbAction += full[4];
return tbAction;
}
},
{
sWidth: "3%",
bSortable: false,
mRender: function (data, type, full) {
var tbAction = '';
tbAction += full[5];
return tbAction;
}
},
{
sWidth: "3%",
bSortable: false,
mRender: function (data, type, full) {
var tbAction = '';
tbAction += full[6];
return tbAction;
}
},
{
sWidth: "3%",
bSortable: true,
mRender: function (data, type, full) {
var tbAction = '';
tbAction += full[12];
return tbAction;
}
},
],
createdRow: function(row, data, dataIndex) {
$compile(row)($scope)
}
};