columns.searchPanes.options
自:SearchPanes 1.0.0 起
定義自訂搜尋選項。
請注意 - 此屬性需要 DataTables 的 SearchPanes 擴充套件。
描述
預設情況下,SearchPanes 不會將任何自訂選項新增至窗格。
當 columns.searchPanes.options.value
是一個函式時,會在搜尋表格時使用此函式。此函式接收以下參數。
rowData
- 從目前要比較的列中取得的資料,為一個陣列,其中包含來自每個欄位的一個元素rowIdx
- 目前要比較的列的索引
該函式的上下文是主機 DataTable 的 API 實例。這表示在自訂搜尋函式中,可以呼叫 API 方法,例如 this.rows().data()
。
如果該列要包含在搜尋結果中,則該函式必須傳回 true
,如果不要則傳回 false
。
當您想要新增一個選項來搜尋表格中沒有的值時,這很有用。例如,「歐洲的國家」或「不是愛丁堡的城市」或年齡範圍。
類型
陣列
- 描述
columns.searchPanes.options
陣列接受以下形式的物件。columns.searchPanes.options.label
屬性是一個字串
,其中包含將顯示在窗格中的值。columns.searchPanes.options.value
的類型為函式
。{ label: string, value: function }
預設值
- 值:
undefined
columns.searchPanes.options
的預設值是 undefined。如果沒有定義自訂選項,則不會將任何選項新增至窗格。
範例
為特定窗格定義自訂選項
var dt = new DataTable('#myTable', {
layout: {
top1: {
searchPanes: {
viewTotal: true,
columns: [0, 3, 4]
}
}
},
columnDefs: [
{
searchPanes: {
options: [
{
label: 'Under 20',
value: function (rowData, rowIdx) {
return rowData[4] < 20;
}
},
{
label: '20 to 30',
value: function (rowData, rowIdx) {
return rowData[4] <= 30 && rowData[4] >= 20;
}
},
{
label: '30 to 40',
value: function (rowData, rowIdx) {
return rowData[4] <= 40 && rowData[4] >= 30;
}
},
{
label: '40 to 50',
value: function (rowData, rowIdx) {
return rowData[4] <= 50 && rowData[4] >= 40;
}
},
{
label: '50 to 60',
value: function (rowData, rowIdx) {
return rowData[4] <= 60 && rowData[4] >= 50;
}
},
{
label: 'Over 60',
value: function (rowData, rowIdx) {
return rowData[4] > 60;
}
}
]
},
targets: [4]
},
{
searchPanes: {
options: [
{
label: 'Not Edinburgh',
value: function (rowData, rowIdx) {
return rowData[3] !== 'Edinburgh';
}
},
{
label: 'Not London',
value: function (rowData, rowIdx) {
return rowData[3] !== 'London';
}
}
],
combiner: 'and'
},
targets: [3]
}
],
select: {
style: 'os',
selector: 'td:first-child'
},
order: [[1, 'asc']]
});
相關
以下選項直接相關,也可能在您的應用程式開發中很有用。