Range search in DataTable for a particular column
Range search in DataTable for a particular column
lovedhaka
Posts: 6Questions: 4Answers: 1
Hello,
I have a column known as Days Extracted i need a way where in i can get the Javascript (not the jQuery) code which i can use to achieve this.
I looked at the following example
https://datatables.net/examples/plug-ins/range_filtering.html
I need to do exactly this thing but through a select box and Javascript .
PFA the image.
Here is my code below.
var columnDays = this.api().column(12); //12 is the column index for Days Extracted
$('<select><option value="">--Select Days Extracted--</option><option value="0">0 TO 5</option><option value="6">6 TO 10</option><option value="11">11 TO 15</option><option value="16">16 TO 20</option><option value="21">21 TO 25</option><option value="26">26 TO 30</option></select>')
.appendTo($('#filterDays'))
.on('change',function () {
var min = parseInt($.fn.dataTable.util.escapeRegex(
$(this).val()
));
var max = min + 5;
if(min == 0){
max = 6;
}
columnDays.search().draw(); // i need help here..
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
You have to provide an argument within the
column().search()
Alternatively, give YADCF a look.
Actually range filtering is a little bit beyond the
column().search()
method at the moment I'm afraid. You need to use a search plug-in. It is a function that you control, so it can get its inputs from anywhere, includingselect
elements, but you need to define its logic and where it gets data from.Allan
But if you explode that range into an array, 0-5 becomes [0,1,2,3,4,5],
column().search()
can accept that.Hey Allan, how to manage range filtering in server-side processing mode?
You would need to have your server-side script accept the range values and apply a suitable condition to the query it uses. You can use
ajax.data
to send extra values to the server.Allan