loop with columns.searchPanes.options
loop with columns.searchPanes.options
I have probably more a javascript question than its belonging to searchpanes or datatables.
I am using custom searchpanes for creating a dynamic panes.
I have an array with 170 strings and this would lead to following code:
{
data: dataColumns[2].data,
title: dataColumns[2].title,
searchPanes: {
options: [
{label: 'Car', value: (rowData, rowIdx) => (rowData.sub.match(/car/i))},
{label: 'House', value: (rowData, rowIdx) => (rowData.sub.match(/house/i))},
//..170 times
{label: 'Sea', value: (rowData, rowIdx) => (rowData.sub.match(/sea/i))}
]
}
}
--> Test-Case
Interestingly the performance does not suffer even with 170 calls
Thats not very pretty and would me lead to a lot of edits, if something changes in my search strings.
Is there a better & working way with a loop by iterating the searchArray (included as comment block in test-case)?
Worked on that the whole day - was not able to get in run because of the options.value() function.
var searchArr = ['Car', 'House', 'Sea']
{
data: dataColumns[2].data,
title: dataColumns[2].title,
searchPanes: {
options: [
function(){
let retObj = {}
searchArr.map(function (myEl) {
let singleObj = {
label: myEl,
value: function(rowData, rowIdx) {
return rowData.sub.match(/myEl/i);
}
}
retObj += singleObj
})
return retObj
}(),
}
}
Thanks in advance.
This question has an accepted answers - jump to answer
Answers
I did something similar to what you were doing, but by building up the options before initialising the table - see your updated example here.
The 'interesting' bit of the code is here:
Hope that helps,
Colin
@colin thats exactly what i was looking for - perfect!
Just tested with my environment - working flawlessly and fast.
Thank you so much.
For just the case, if someone else stumping over this - I slightly adapted it here to make it a bit more flexible per function call.