search/filter on specific columns only - not working
search/filter on specific columns only - not working
genealogy_guy
Posts: 10Questions: 0Answers: 0
Have spent a few days getting my head around this DataTables v1.8 and am very impressed. Just need assistance with two problems.
My database table consists of addresses - state, county, town, aka_town, street, zip code. I am using the following to display/format my table:
[code]
$(document).ready(function() {
$('#example').dataTable( {
"aaSorting": [[ 2, "asc" ]],
"aLengthMenu": [10, 25, 50],
"sPaginationType": "full_numbers",
"aoColumnDefs": [
/* State */
{ "sName": "state", "aTargets": [ 0 ] },
{ "bSearchable": false, "aTargets": [ 0 ] }, /* do NOT search this field/column */
/* County */
{ "sName": "county", "aTargets": [ 1 ] },
{ "bSearchable": false, "aTargets": [ 1 ] }, /* do NOT search this field/column */
/* Town */
{ "sName": "town", "aTargets": [ 2 ] },
/* AKA_Town - other name for Town */
{ "sName": "aka_town", "aTargets": [ 3 ] },
{ "bVisible": false, "aTargets": [ 3 ] }, /* hide this field/column - still searchable */
/* Street */
{ "sName": "street", "aTargets": [ 4 ] },
/* Zip */
{ "sName": "zip", "aTargets": [ 5 ] },
{ "sClass": 'center', "aTargets": [ -4, -4 ] },
/* Combine Town & AKA_Town as needed */
{ "fnRender": function ( oObj ) {
if ( oObj.aData[3] != "" ) {
return oObj.aData[2] +'
a.k.a.
'+ oObj.aData[3];
}
else {
return oObj.aData[2];
}
},
"aTargets": [ 2 ]
},
],
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "scripts/server_processing.php",
"fnServerData": fnDataTablesPipeline /* This is used to load 5 screens of data - less server processing */
} );
} );
[/code]
Problem 1: - If I enter "tex" in search field, the results include states with "tex", as well as county, town & street.
I would like my global search to NOT search state and county, only search town, aka_town, street and zipcode. Can somebody see what is wrong in my code???
Problem 2: - I would like to be able to have select/drop-down for first two columns only - state & county. I would like filter boxes for other columns for user to enter their preferred values to search for. In the examples, there is one example where all columns have drop-down boxes. In another example, all columns have search-entry or filter boxes. Is it possible to have some columns with drop-down boxes and some-other columns (not all) with search-entry boxes?
Love this technology. It will be ideal if I can get these two small problems resolved.
Regards
Genealogy Guy
My database table consists of addresses - state, county, town, aka_town, street, zip code. I am using the following to display/format my table:
[code]
$(document).ready(function() {
$('#example').dataTable( {
"aaSorting": [[ 2, "asc" ]],
"aLengthMenu": [10, 25, 50],
"sPaginationType": "full_numbers",
"aoColumnDefs": [
/* State */
{ "sName": "state", "aTargets": [ 0 ] },
{ "bSearchable": false, "aTargets": [ 0 ] }, /* do NOT search this field/column */
/* County */
{ "sName": "county", "aTargets": [ 1 ] },
{ "bSearchable": false, "aTargets": [ 1 ] }, /* do NOT search this field/column */
/* Town */
{ "sName": "town", "aTargets": [ 2 ] },
/* AKA_Town - other name for Town */
{ "sName": "aka_town", "aTargets": [ 3 ] },
{ "bVisible": false, "aTargets": [ 3 ] }, /* hide this field/column - still searchable */
/* Street */
{ "sName": "street", "aTargets": [ 4 ] },
/* Zip */
{ "sName": "zip", "aTargets": [ 5 ] },
{ "sClass": 'center', "aTargets": [ -4, -4 ] },
/* Combine Town & AKA_Town as needed */
{ "fnRender": function ( oObj ) {
if ( oObj.aData[3] != "" ) {
return oObj.aData[2] +'
a.k.a.
'+ oObj.aData[3];
}
else {
return oObj.aData[2];
}
},
"aTargets": [ 2 ]
},
],
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "scripts/server_processing.php",
"fnServerData": fnDataTablesPipeline /* This is used to load 5 screens of data - less server processing */
} );
} );
[/code]
Problem 1: - If I enter "tex" in search field, the results include states with "tex", as well as county, town & street.
I would like my global search to NOT search state and county, only search town, aka_town, street and zipcode. Can somebody see what is wrong in my code???
Problem 2: - I would like to be able to have select/drop-down for first two columns only - state & county. I would like filter boxes for other columns for user to enter their preferred values to search for. In the examples, there is one example where all columns have drop-down boxes. In another example, all columns have search-entry or filter boxes. Is it possible to have some columns with drop-down boxes and some-other columns (not all) with search-entry boxes?
Love this technology. It will be ideal if I can get these two small problems resolved.
Regards
Genealogy Guy
This discussion has been closed.
Replies
instead of:
[code]
{ "sName": "state", "aTargets": [ 0 ] },
{ "bSearchable": false, "aTargets": [ 0 ] }, /* do NOT search this field/column */
[/code]
use:
[code]
{ "sName": "state", "aTargets": [ 0 ] , "bSearchable": false }, /* do NOT search this field/column */
[/code]
[code]{ "aTargets": [ 0 ] , "sName": "state", "bSearchable": false }, /* do NOT search this field/column */
{ "aTargets": [ 1 ] , "sName": "county", "bSearchable": true }[/code]
When I try to search the message "processing..." appears and nothing happens.
I think there is a column that the filtering cannot handle.
I am trying to tell the search(filtering) to do not use the other columns except for one.
Still cannot make it work :P