Column filtering with select inputs
Column filtering with select inputs
Hello, I want to add column filtering to my datatables as on this example https://datatables.net/extensions/fixedheader/examples/options/columnFiltering.html but instead of search inputs I added select inputs.
I want to check the unique values of each column and append the values as options inside my select.
Basically what I did :
clone tr in theadand give it an id
foreach th I append a select
on initComplete i check unique values of each column liveTable.columns( k ).data().eq( 0 ).unique().sort()
loop through the unique array and add each item between option tag
append all the options inside my select
I am getting the error jquery.dataTables.min.js:30 Uncaught TypeError: Cannot read property 'sDefaultContent' of undefined
I commented my code so that you have a clear explanation. Any suggestions please what I am doing wrong ? Thank you very much.
here is the demo link on jsfiddle https://jsfiddle.net/zkyL6ca2/1/
Answers
Because you're cloning the select elements, you have 44 of them. So, when you iterate through on line 53, you're incrementing
kbeyond the 22 columns, meaningcolumns(k)on line 57 in invalid above 21.Colin
I see the issue but when i use $('#liveTable thead tr:eq(1) th .added').each(function() {... }); it will loop only through the select inputs I need but then it doesn't append the options. it shows only all. any ideas why please ? here is the updated jsfiddle https://jsfiddle.net/b1Lc9j2f/
Thank you
i figured it out. it should be $("tr:eq(1) th:eq(" + k + ") .added").append(option);