AJCastuera / jquery-datatables-column-filter

Automatically exported from code.google.com/p/jquery-datatables-column-filter
0 stars 0 forks source link

Select filter does a "contains" search rather than an "equals" search #137

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Set up a regular select filter on a column with the values "Test 1", "Test 
2" and "Test 10"
2. Select "Test 1" from the select filter

What is the expected output? 
Only rows with the value of "Test 1" in that column should be shown

What do you see instead?
Rows with the values "Test 10" are show along with "Test 1"

What version of the product are you using? On what operating system?
Windows 7, IE9 and Chrome.
Version 1.5.1

Please provide any additional information below.

To fix the problem for my situation I did two things:

1. line 377
from: oTable.fnFilter($(this).val(), iColumn, bRegex); //Issue 41
to:   oTable.fnFilter($(this).val() ? "^" + unescape($(this).val()) + "$" : 
$(this).val(), iColumn, bRegex);

2. I added "bRegex:true" to my options when calling columnFilter.

This fixed the problem for my purposes, however, I'm not sure how this would 
work when someone is actually trying to use a regular expression (since I 
called unescape())

This issue is similar to issue 68, but has a substantive difference. He was 
searching for "Test 1" and getting all result with "Test" in them. I'm only 
getting all results with "Test 1" in them.

I would suggest fully vetting how my solution would effect actual regex 
expression. If it is compatible with regex expression then this solution is 
fine.

However if it is not, as I suspect I would suggest either of the following two 
solutions.

1. Change the designed functionality for selects to exact match. This means 
that if bRegex is FALSE would would use oTable.fnFilter($(this).val() ? "^" + 
unescape($(this).val()) + "$" : $(this).val(), iColumn, bRegex); and if bRegex 
is true you would use your current line 377. Using a select for a "contains" or 
"like" search would no longer be supported.

2. Add an option for exact search. If the bRegex is false and bExact is true 
then use my new line: oTable.fnFilter($(this).val() ? "^" + 
unescape($(this).val()) + "$" : $(this).val(), iColumn, bRegex); and if bRegex 
is false and bExact is false use your current line 379. If bRegex is true then 
bExact would not be supported (I don't see how it would make sense for regular 
expressions). if bRegex was true, ignore bExact and use your current line 377. 
You could even set the default value of bExact as false for perfect backwards 
compatibility. (However, I think you'll find most people expect a select filter 
to work as bExact = true.)

If I can be of any additional help, or if I have missed something and there is 
a setting currently that supports this functionality please let me know.

Great project! It has been immensely helpful!

Original issue reported on code.google.com by kralco...@gmail.com on 23 Oct 2013 at 2:28

GoogleCodeExporter commented 8 years ago
JQuery DataTables - Filter column by exact match
oTable.fnFilter( "^"+TERM+"$", COLUMN , true); //Term, Column #, RegExp Filter

$(document).ready(function() {
    tbl = $('#example').dataTable();
    tbl.fnFilter("^" + filter_value + "$");
});

$(document).ready( function() {
    $('#example').dataTable( {
        "oSearch": {"bSmart": false}
    } );
} )

Original comment by mrkraju1...@gmail.com on 13 Feb 2014 at 9:53