Problem with column filter plugin and regexp in select box

Problem with column filter plugin and regexp in select box

PaladiumPaladium Posts: 3Questions: 0Answers: 0
edited October 2011 in Plug-ins
Hi there,

I really like the datatables and the plugin column filter, but I habe one serious probem.
I have one column that contain the Bundeslaender (states) of gemany for each user in a row.
There are some states that contain the name of one special state: "Sachsen".
So when I filter with the selectbox Sachsen, also other states are found: "Niedersachsen" or Sachsenanhalt.
I know that regexp is the key for solving this problem and tried a lot, but nothing helped.
I really need help right now, I don't know what else to do. I am not that familiar with javascript, but most of the time I understand the code.

Here are my Codes:
jquery.dataTables.columnFilter.js:
=====================
[code]select.change(function () {
//var val = $(this).val();
if ($(this).val() != "") {
$(this).removeClass("search_init");
} else {
$(this).addClass("search_init");
}
top.alert("^"+unescape($(this).val())+"$"); //just to see how it looks
//oTable.fnFilter("^"+$(this).val()+"$", index, true, false); //try 1
oTable.fnFilter(unescape($(this).val()), index, true, false, false); //another try
top.alert(oTable.fnFilter); //just to so what happens
fnOnFiltered();
});[/code]

The HTML Table Page:
==============
[code]



Statistik

@import "./css/demo_page.css";
@import "./css/demo_table_jui.css";
@import "./cacherstats/jquery-ui-1.8.16.custom.css";







$(document).ready(function() {
$('#example').dataTable( {
bJQueryUI: true,
iDisplayLength: 20,
"aLengthMenu": [[20], [20]],
"aaSorting": [[5,'asc']],
"bInfo": false,
"sPaginationType": "full_numbers",
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "blahbluhblibb.php"
} );
} );




$(document).ready(function(){
$('#example').dataTable()
.columnFilter({
aoColumns: [
{ type: "text" },
null,
null,
null,
{ type: "select", values: [ 'Baden-Württemberg', 'Bayern', 'Berlin', 'Brandenburg', 'Bremen', 'Hamburg', 'Hessen', 'Mecklenburg-Vorpommern', 'Niedersachsen', 'Nordrhein-Westfalen', 'Rheinland-Pfalz', 'Saarland', 'Sachsen', 'Sachsen-Anhalt', 'Schleswig-Holstein', 'Thüringen'] },
null,
null,
null
]
});
});


var oTable;

$(document).ready(function() {
oTable = $('#example').dataTable();

/* Filter immediately */
oTable.fnFilter( 'Nordrhein-Westfalen',4 );
} );







Team
Finds
Hides
Chall.
B-Land
Rang Finds
Rang Hides
Rang Chall.




Loading data from server




Team
Finds
Hides
Chall.
B-Land
Rang Finds
Rang Hides
Rang Chall.





[/code]

Here is a photo.
http://www.myimagespace.com/public/view/full/7962

Any help is appreciated. Thanks in advance.

Markus
Markus

Replies

  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    The default server side script does not check for reg expressions. You will need to modify the script.

    see my blog entry at http://tote-magote.blogspot.com/

    [code]
    if (isset($_GET['sSortable_'.$i]) && $_GET['sSortable_'.$i] == "true") {
    if (isset($_GET['bRegex_'.$i]) && $_GET['bRegex_'.$i] == "true")
    $sWhere .= $aColumns[$i]." REGEXP '".mysql_real_escape_string( $_GET['sSearch'] )."' OR ";
    else
    $sWhere .= $aColumns[$i]." LIKE '%".mysql_real_escape_string( $_GET['sSearch'] )."%' OR ";
    }
    }
    [/code]
  • PaladiumPaladium Posts: 3Questions: 0Answers: 0
    Thank you for your help fbas, but do you mean the php-script that creates the json data?
    If yes, can you tell me where exactly i have to put your code?

    Does this change in code also change the behaviour of the text-search?
    It should only be changed on the select<->option search.

    Thanks in advance.
    Markus
  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    it will work only when DataTables sends $bRegex_{$i} = true, i.e. when you call fnFilter() with regex=true, as you have done manually only for the select.

    read the blog entry to find where to change the code.
This discussion has been closed.