0
如何在initComplete事件上重新初始化jquery數據表。 我已經在initComplete中添加了一個ajax調用並且想要替換數據表中的數據我該如何做到這一點有沒有人有想法?如何重新初始化initComplete上的jquery數據表?
這是我的代碼。
$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)
}
};
這是沒有意義的。您正在嘗試加載表格,然後在用戶甚至可以查看之前自動重新加載它?我不清楚你想要完成什麼。 – Bindrid
加載我有加載數據表,但現在按鈕單擊我添加ajax調用,然後我想更改數據表數據,所以我怎麼能做到這一點? –