Search for the columns having the dropdown list
Search for the columns having the dropdown list
Hello,
I have a datatable where it has the columns contains the dropdowns. I am unable to search the table based on the selected values of those dropdowns.
I am looking for the implementation which is similar to the below,
$.fn.dataTableExt.ofnSearch['html-input'] = function(value) {
return $(value).val();
};
var table = $("#example").DataTable({
columnDefs: [
{ "type": "html-input", "targets": [1, 2, 3] }
]
});
This is in the old version of datatable. I am using the datatable version 1.10.3.
I have tried the below way but didnt workout for me.
$.fn.dataTable.ext.type.search.html = function (d) {
return $(d).val();
};
Thanks & Regards,
Bhargava
Replies
Hi bhargavakl,
I'm afraid that at the moment DataTables does not support this using the API or otherwise. It is however possible to accomplish this by writing your own function. You would need to define your own search box too.
You can find some details on writing a custom filtering function here.
Thanks,
Sandy
Hello @sandy,
Thanks for your inputs. Even I tried with this approach. But my table has too many columns to search.
Hence I went on to do this, with my custom search, without using the datatable in-built search function.
Thanks,
Bhargava
Have you seen this example?
https://datatables.net/examples/api/multi_filter_select.html
Kevin
Hello @kthorngren,
Thanks for the link. It's looking good though. But the user wanted only the global search box instead of the controls on the footer to search the table.
I have tried more towards the datatable extensions, which unable to yield the result.
The only problem in my table is the dropdowns, rest all the search works fine (thanks to the datatable fantastic search feature). Datatable search is unable to search the dropdown's selected value.
I am constructing my dropdown as below,
Please do let me know anybody tried this earlier. It helps a lot.
Thanks & Regards,
Bhargava
Edited by Kevin: Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
It looks like you are trying to put the drop down search in each row of the table. Is this what you want to do?
Kevin
Hello @kthorngren,
It's not the dropdown search in each row of the table, column 2 contains the dropdowns where user can select the data and save it. Basically, I am doing the inline edit datatable where dropdown is the part of the data selection in column 2.
here is my entire table's columnDefs,
Please have a look and let me know any idea on the same.
Thanks & Regards,
Bhargava
I don't see where you have tried to implement the drop down search. The example I linked to builds the search drop down from the data in the column. Are you asking how to generate the search drop down list from
row.actionList
for column 2?Kevin