Multiple terms filtering
Multiple terms filtering
Hi,
I'm trying to implement a multiple terms filtering on my datatable. I have three select dropdowns that have an onchange event which triggers fnFilter with the selected value. Each one filters the table according to the selected value, but what I would like is that all three selected terms get filtered.
I guess, simply put, is there a way to filter for example : apple + pears + bananas
Which would show only the table rows that have these three terms.
Thanks for the help
I'm trying to implement a multiple terms filtering on my datatable. I have three select dropdowns that have an onchange event which triggers fnFilter with the selected value. Each one filters the table according to the selected value, but what I would like is that all three selected terms get filtered.
I guess, simply put, is there a way to filter for example : apple + pears + bananas
Which would show only the table rows that have these three terms.
Thanks for the help
This discussion has been closed.
Replies
All you need to do is concatenate your search terms together, and have them space separated. In your example you would do: fnFilter( "apple pears bananas" ); and that would filter to just row with those three terms.
Regards,
Allan
Thanks for the quick reply.
How can I transpose that to my onchange functions ?
Right now, what I have is three onchange events, one for each of my select dropdowns :
[code]$('#dropdown_1').change( function() { oTable.fnFilter( $(this).val() );} );[/code]
I guess I need a variable to store the values of the three selected elements, and then a button to throw that into the filter. Any idea as to how I could do that ?
Thanks
Can you not just get the value of each dropdown in the change event? So for example:
[code]
function fnThreeWayFilter()
{
/* Get the filter values */
var filter1 = $('#dropdown_1').val();
var filter2 = $('#dropdown_2').val();
var filter3 = $('#dropdown_3').val();
var filter = "";
/* Concat them together */
if ( filter1 != "" )
{
filter += filter1+" ";
}
if ( filter2 != "" )
{
filter += filter2+" ";
}
if ( filter3 != "" )
{
filter += filter3+" ";
}
/* Drop the last space */
if ( filter != "" )
{
filter = filter.replace(/ $/, "");
}
oTable.fnFilter( filter );
}
$('#dropdown_1').change( fnThreeWayFilter );
$('#dropdown_2').change( fnThreeWayFilter );
$('#dropdown_3').change( fnThreeWayFilter );
[/code]
Of course, there are many other ways to do this - but this is one option if you have full control over the three select elements :-)
Regards,
Allan