DataTables Individual Column Searching using column().search().draw() Problem (server-side)
DataTables Individual Column Searching using column().search().draw() Problem (server-side)
rgwenceslao
Posts: 4Questions: 0Answers: 0
I found this solution (https://datatables.net/examples/api/multi_filter.html) to my requirement but when I tried to use it, it seems to trigger my server-side event but fails to apply a column search. Also, the keyup and change events are triggered twice - first is the column index of my column search textbox and the second, a hidden column which the DataTable uses for its default sorting. I hope someone can help me here.
$(document).ready(function(){
$('#mlTable tfoot th').each( function () {
var title = $('#mlTable thead th').eq( $(this).index() ).text();
$(this).html( '<input type="text" placeholder="Search '+title+'" />' );
} );
var myListingsDTVariable = $('#mlTable').DataTable( {
"processing": true,
"serverSide": true,
"ajax": setProjectName + "/dataTablesMyListings?divisionValue=1",
"columns": [
{ "data": "checkbox", "name" : "checkbox", "sortable" : false },
{ "data": "status", "name": "status" },
{ "data": "id", "name": "id" },
{ "data": "category", "name": "category" },
{ "data": "type", "name": "type" },
{ "data": "address", "name" : "address" },
{ "data": "price", "name" : "price" },
{ "data": "bedrooms", "name" : "bedrooms" },
{ "data": "floor", "name" : "floor" },
{ "data": "lot", "name" : "lot" },
{ "data": "furnished", "name" : "furnished" },
{ "data": "contact", "name" : "contact" },
{ "data": "availabilityDate", "name" : "availabilityDate" },
{ "data": "dateModified", "name" : "dateModified" }
],
"order": [[ 13, "desc" ]],
"oLanguage": {
"sSearch": "Filter: ",
"sZeroRecords": "No properties found.",
"sLengthMenu": 'Display <select>'+
'<option value="10">10</option>'+
'<option value="20">20</option>'+
'<option value="30">30</option>'+
'<option value="40">40</option>'+
'<option value="50">50</option>'+
'<option value="-1">All</option>'+
'</select> properties',
"sInfoFiltered": " (filtered from _MAX_ properties)",
"sInfoEmpty": "No properties to show",
"sInfo": "Showing _START_ to _END_ of _TOTAL_ properties"
},
"columnDefs": [
{
"targets": [ 13 ],
"visible": false,
"searchable": false
}
]
});
// Apply the search
myListingsDTVariable.columns().eq( 0 ).each( function ( colIdx ) {
$( 'input', myListingsDTVariable.column( colIdx ).footer() ).on( 'keyup change', function () {
alert(colIdx); // check what index was triggered, unfortunately, column 13 is also triggered everytime
myListingsDTVariable.column( colIdx ).search( this.value ).draw();
} );
} );
});
<table id="mlTable" class="order-column row-border hover">
<thead>
<tr>
<th></th>
<th>Status</th>
<th>ID</th>
<th>Category</th>
<th>Type</th>
<th>Address</th>
<th class="priceHeader">Price</th>
<th class="bedroomHeader">Bedrooms</th>
<th>Floor</th>
<th>Lot</th>
<th>Furnishing</th>
<th>Contact</th>
<th>Availability</th>
</tr>
</thead>
<tbody id="mlTableBody">
</tbody>
<tfoot>
<tr>
<th></th>
<th>Status</th>
<th>ID</th>
<th>Category</th>
<th>Type</th>
<th>Address</th>
<th>Price</th>
<th>Bedrooms</th>
<th>Floor</th>
<th>Lot</th>
<th>Furnishing</th>
<th>Contact</th>
<th>Availability</th>
</tr>
</tfoot>
</table>
This discussion has been closed.
Replies
Here's my server-side code snippet for searching/filtering part:
I am using SOLR that's why this is the format. I append searchValue to my SOLR query after this.
I would suggest dumping the generated query out to a text file that you can inspect. Then you can check to see if the column search is being included in the query.
Allan
Hi Allan,
Thanks for your reply. I am performing System.out.println() within the class but I don't see any changes to the search parameter. Would you know the specific variable to use for column searches? I only have the variable for global searching.
Please don't post the same question in multiple threads. I've just replied to your question about this is a different thread.
The manual contains a list of the parameters that the client-side sends to the server.
Allan
can it possible to place the search fields on the opt of the table. or below the header and it may be placed on the first row of data. any code samples. please help me on that one.