0
數據表列的可見性(「數據表指的是jQuery的Data Tables產品。)如何設置特定表
在這種情況下,我需要選擇顯示或隱藏特定表的列(出三在特定頁面上表)。當我運行該腳本,我得到一個jQuery控制檯錯誤Cannot read property 'bVisible' of undefined
。
現有論壇答案涉及到的.DataTable()
正確的拼寫。這是不是這裏的問題。
根據現有的documentation,我正確定義oTable
,但也許文檔假定我只有一個表(我有三個)。有什麼我應該做的,以便表格被正確定義?
function setVisibleColumnsAverage() {
$("#LoadingMessage").modal("show");
var headers = ["Not Rated", "Target", "Ongoing", "Complete"];
var status = $("#InterventionStatus").val();
// Below is the relevant Data Table code
var oTable = $(".display").DataTable();
for (var j = 0; j < status.length; j++) {
for (var i = 0; i < headers.length; i++) {
if (status[j] === "Not Rated" && headers[i] === "Not Rated") {
oTable.table("#InterventionAverage").column(4).visible(true, false);
oTable.table("#InterventionAverage").column(9).visible(true, false);
}
if (status[j] === "Target" && headers[i] === "Target") {
oTable.table("#InterventionAverage").column(5).visible(true, false);
oTable.table("#InterventionAverage").column(10).visible(true, false);
}
if (status[j] === "Ongoing" && headers[i] === "Ongoing") {
oTable.table("#InterventionAverage").column(6).visible(true, false);
oTable.table("#InterventionAverage").column(11).visible(true, false);
}
if (status[j] === "Complete" && headers[i] === "Complete") {
oTable.table("#InterventionAverage").column(7).visible(true, false);
oTable.table("#InterventionAverage").column(12).visible(true, false);
}
}
}
oTable.columns.adjust().draw(false);
}
我曾嘗試用同樣結果的其它變體,如:
var oTable = $(".display").DataTable();
var table1 = oTable.table("#InterventionAverage");
for (var j = 0; j < status.length; j++) {
for (var i = 0; i < headers.length; i++) {
if (status[j] === "Not Rated" && headers[i] === "Not Rated") {
table1.column(4).visible(true, false);
table1.column(9).visible(true, false);
}
if (status[j] === "Target" && headers[i] === "Target") {
table1.column(5).visible(true, false);
table1.column(10).visible(true, false);
}
if (status[j] === "Ongoing" && headers[i] === "Ongoing") {
table1.column(6).visible(true, false);
table1.column(11).visible(true, false);
}
if (status[j] === "Complete" && headers[i] === "Complete") {
table1.column(7).visible(true, false);
table1.column(12).visible(true, false);
}
}
}