External Filter Trigger
External Filter Trigger
I have been searching for this answer for weeks so finally decided to ping community in hopes I am pointed in the right direction. I have a DataTable I have been using for awhile. My goal is to have an external trigger that would have between 4-20 keywords that each would toggle on and off a filter for that word.
Example:
My column is Country, but externally I would like to list Denmark | USA | England | Russia | Ukraine
Each word would then become a trigger on/off whether that country is listed in the DataTable.
Any ideas or docs I could look at to research this?
FWIW this is what my current configuration looks like:
//DataTables options
var table = $('#salesdata').DataTable({
"statesave":false,
"colReorder": false,
"ordering": true, // false to disable sorting (or any other option)
"paging": false,
"responsive": false,
"order": [[ 10, "desc" ]],
"scrolling":true,
"bInfo": false,
"iDisplayLength": 50,
"bJQueryUI": true,
"bStateSave": false,
"sScrollY": true,
"bFilter": true,
"bDeferRender": true,
"fixedHeader": [{
header: true,
footer: false
}],
columnDefs: [{
orderSequence: [ "desc", "asc"],
targets: ["_all"],
},
{
orderable: false,
targets: [0,1,2,3,14],
}],
})
Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
This question has an accepted answers - jump to answer
Answers
Best way would be to do this in
initComplete
, and get the table's data withdata = table.data().unique().toArray()
. Then cycle through the buttons with$.each()
, and calldata.indexOf(buttonString)
, and if it's-1
,this.attr('disabled','disabled');
Should do the trick,
Colin