Filter on user input AND defined value
Filter on user input AND defined value
I've been trying to get this to work for some time with no success.
Each row details a program that is available in multiple cities. One of the columns in the row holds all the city information. However, some of the programs don't have a specific city, as they are available everywhere, so there is a default value of "throughout province".
I would like to allow users to enter the city they are searching and get those results AND all records with the value "throughout".
Is this possible? The following code works for searching on cities. I've trying adding different things to the var iColumn line but was never able to get it to show the city AND records with "throughout".
[code]
function fnFilterLocation ()
{
var jqInputs = $('#filter_location input');
var iColumn = jqInputs[1].value == "" ? null : jqInputs[1].value;
oTable.fnFilter( jqInputs[0].value, 4 );
}
[/code]
Thanks for any help you can provide!!
Each row details a program that is available in multiple cities. One of the columns in the row holds all the city information. However, some of the programs don't have a specific city, as they are available everywhere, so there is a default value of "throughout province".
I would like to allow users to enter the city they are searching and get those results AND all records with the value "throughout".
Is this possible? The following code works for searching on cities. I've trying adding different things to the var iColumn line but was never able to get it to show the city AND records with "throughout".
[code]
function fnFilterLocation ()
{
var jqInputs = $('#filter_location input');
var iColumn = jqInputs[1].value == "" ? null : jqInputs[1].value;
oTable.fnFilter( jqInputs[0].value, 4 );
}
[/code]
Thanks for any help you can provide!!
This discussion has been closed.
Replies
I think you are looking for OR rather than AND are you not? Either this city OR 'throughout'. Try:
[code]
oTable.fnFilter( 'throughout|'+jqInputs[0].value, 4, false );
[/code]
So what this is saying is don't escape regular expression characters (the false) and filter for 'throughout' or jqInputs[0].value on column index 4.
Allan
Thanks again :)
Something like this?
[code]oTable.fnFilter( 'throughout|'+jqInputs[0].value, 4|5, false );[/code]
That didn't work and I've tried a few other things, but I'm not having any luck
Thanks!
Laura
If anyone else is trying this here is my code on a simple filter:
[code]oTable.fnFilter( jqInputs[0].value, [3][4] );[/code]
Allan
[code]
var oTable;
function fnFormatDetails ( nTr )
{
var aData = oTable.fnGetData( nTr );
var sOut = '';
sOut += ' Services'+aData[3]+'';
sOut += ' Eligibility'+aData[4]+'';
sOut += ' Locations'+aData[5]+'';
sOut += ''+aData[6]+'';
sOut += '';
return sOut;
}
function fnFilterServices ()
{
var jqInputs = $('#filter_services input');
var iColumn = jqInputs[1].value == "" ? null : jqInputs[1].value;
oTable.fnFilter( jqInputs[0].value, [3][4] );
}
function fnFilterLocation ()
{
var jqInputs = $('#filter_location input');
var iColumn = jqInputs[1].value == "" ? null : jqInputs[1].value;
oTable.fnFilter( 'throughout|'+jqInputs[0].value, 5, false );
}
$(document).ready(function() {
oTable = $('#inventory').dataTable( {
"aoColumns": [
{ "sWidth": "70px", "bSortable": false},
{ "sWidth": "400px" },
{ "sWidth": "460px", "sType": "html", "bSortable": false },
{ "bVisible": false, "bSortable": false },
{ "bVisible": false, "bSortable": false },
{ "bVisible": false, "bSortable": false },
{ "bVisible": false, "bSortable": false }
],
"aaSorting": [[1, 'asc']],
"bPaginate": false,
"bInfo": true,
"bLengthChange": false,
"bFilter": false
});
$('#filter_services input').keyup( fnFilterServices );
$('#filter_location input').keyup( fnFilterLocation );
$(oTable.fnGetNodes() ).each( function () {
$(this).click( function () {
var nTr = this;
if ( $(this).hasClass('row_selected') )
{
$(this).removeClass('row_selected');
oTable.fnClose( nTr );
}
else
{
$(this).addClass('row_selected');
oTable.fnOpen( nTr, fnFormatDetails(nTr), 'details' );
}
} );
} );
} );
[/code]
Allan
I guess this can't be done the way I have it... I'm stumped :(
Thanks for pointing that out