我在一個Angular2項目中使用DataTables serverSide。帶參數的DataTables ajax.reload()
我想重新加載表進行更改後,我想通過AJAX將這些更改作爲參數傳遞給POST。
的事情是,數據表總是從初始化獲得options
對象,而不是一個更新的版本與新參數。
那麼,我需要的是是,用ajax.reload()
傳遞一組新的參數。
這是我目前的功能:
filterData(tableParams) {
console.log('reloading DT. tableparams received are: ' + JSON.stringify(tableParams));
let element = $(this.el.nativeElement.children[0]);
let table = element.find('table.dataTable');
table.DataTable().ajax.reload();
}
此刻,你可以看到,我沒有使用tableParams
,這是因爲我想展現一個乾淨的版本,我的功能,我試過很多事情並沒有一個工作。
DataTables總是獲取初始參數爲options
的對象。
這是我絕望的嘗試之一:
filterData(tableParams) {
let element = $(this.el.nativeElement.children[0]);
let table = element.find('table.dataTable');
table.DataTable({
ajax: {
url: this.jsonApiService.buildURL('/test_getUsers.php'),
type: 'POST',
data: tableParams,
},
}).ajax.reload();
}
一些幫助,將不勝感激。如果您需要關於如何創建DataTable的更多解釋或更多代碼片段讓我知道。但我認爲這個問題只是在ajax.reload()
函數中,能夠發送更新的參數將解決問題。
非常感謝!
編輯1
這是我的init options
對象:
let data = {
email: true,
test: 'init',
};
this.options = {
dom: 'Bfrtip',
processing: true,
serverSide: true,
pageLength: 20,
searchDelay: 1200,
ajax: {
url: this.jsonApiService.buildURL('/test_getUsers.php'),
type: 'POST',
data: data,
},
columns: [
{data: 'userId'},
{data: 'userCode'},
{data: 'userName'},
{data: 'userRole'},
{data: 'userEmail'},
],
};
而這些是數據表被髮送參數:
(在其他數據表參數)
當我打電話給ajax.reload()
時,無論我嘗試過什麼,我最終都會發送這些相同的參數,因此會發送init參數。