search/filter on specific columns only - not working

search/filter on specific columns only - not working

genealogy_guygenealogy_guy Posts: 10Questions: 0Answers: 0
edited July 2011 in DataTables 1.8
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

Replies

  • genealogy_guygenealogy_guy Posts: 10Questions: 0Answers: 0
    My solution to problem #1 was to concatenate two fields (town, aka_town) in the database into a third field called town1and2. DataTables was set to retrieve three fields amongst others - town (visible/searchable) , aka_town(hidden/searchable), town1and2(hidden/searchable). Function fnRender() was used to format the column values for Town column using the values in town and aka_town. The search filter for that column was tweaked to search the values in the hidden column town1and2.
  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    edited August 2011
    the problem is probably using separate objects referring to the same columns. the system probably ends up clobbering one and only using the other. (this is just a guess, but I think this is the case)

    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]
  • genealogy_guygenealogy_guy Posts: 10Questions: 0Answers: 0
    edited August 2011
    Thats neat. So can that be written as follows:

    [code]{ "aTargets": [ 0 ] , "sName": "state", "bSearchable": false }, /* do NOT search this field/column */
    { "aTargets": [ 1 ] , "sName": "county", "bSearchable": true }[/code]
  • axllaruseaxllaruse Posts: 8Questions: 0Answers: 0
    This is not working for me.
    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
This discussion has been closed.