Allow search in just one column with Asp.Net MVC
Allow search in just one column with Asp.Net MVC
arianit
Posts: 2Questions: 1Answers: 0
Hi, I am using Asp.Net MVC, and I am getting some data from a database (table) into the datatable. And I want to search the records just by their name, not the other columns. How can I archive that, disabling search for specific columns or enabling search for specific columns? (I am using Entity Framework Code-First, if you know it)
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
https://datatables.net/examples/api/multi_filter.html but add qualifier inside .columns() with the class of the column you only wish the logic to be applied
https://github.com/vedmack/yadcf
I found a more easier answer and easier to understand.
Example:
$('#example').dataTable({
"columns": [{
"searchable": true,
"orderable": true
}, {
"searchable": true,
"orderable": true
}, {
"searchable": true,
"orderable": true
}, {
"searchable": false,
"orderable": false
}, {
"searchable": false,
"orderable": false
}, {
"searchable": false,
"orderable": false
}, ]
})
the columns order will be corresponding the order of the columns of the table, so the first column in the jquery will be the first in the table, and so on.
I would suggest https://datatables.net/reference/option/columnDefs.targets for cleaner code.