Permalink
Browse files

Fix 151: Column type was being offset when columns were not searchable

  • Loading branch information...
1 parent d5fb56f commit f3ce2e2d44db8eb43750435c55eb2551b2c6019e @DataTables committed Feb 16, 2013
Showing with 84 additions and 4 deletions.
  1. +12 −2 media/js/jquery.dataTables.js
  2. +12 −2 media/src/core/core.filter.js
  3. +60 −0 media/unit_testing/tests_onhold/1_dom/gh-151.js
@@ -2438,8 +2438,18 @@
*/
function _fnBuildSearchRow( oSettings, aData )
{
- for ( var i=0, len=aData.length ; i<len ; i++ ) {
- aData[i] = _fnDataToSearch( aData[i], oSettings.aoColumns[i].sType );
+ var
+ idx = 0,
+ aoColumns = oSettings.aoColumns;
+
+ // aData is passed in without the columns which are not searchable, so
+ // we need to be careful in getting the correct column type
+ for ( var i=0, len=aoColumns.length ; i<len ; i++ ) {
+ aData[idx] = _fnDataToSearch( aData[idx], aoColumns[i].sType );
+
+ if ( aoColumns[i].bSearchable ) {
+ idx++;
+ }
}
var sSearch = aData.join(' ');
@@ -312,8 +312,18 @@ function _fnBuildSearchArray ( oSettings, iMaster )
*/
function _fnBuildSearchRow( oSettings, aData )
{
- for ( var i=0, len=aData.length ; i<len ; i++ ) {
- aData[i] = _fnDataToSearch( aData[i], oSettings.aoColumns[i].sType );
+ var
+ idx = 0,
+ aoColumns = oSettings.aoColumns;
+
+ // aData is passed in without the columns which are not searchable, so
+ // we need to be careful in getting the correct column type
+ for ( var i=0, len=aoColumns.length ; i<len ; i++ ) {
+ aData[idx] = _fnDataToSearch( aData[idx], aoColumns[i].sType );
+
+ if ( aoColumns[i].bSearchable ) {
+ idx++;
+ }
}
var sSearch = aData.join(' ');
@@ -0,0 +1,60 @@
+// DATA_TEMPLATE: html_table
+oTest.fnStart( "Check type is correctly applied to filtering columns" );
+
+
+$(document).ready( function () {
+ // The second column is HTML type, and should be detected as such, while the first
+ // column is number type. We should get no results, as a test for the bug, when
+ // searching for http
+ $('#example').dataTable( {
+ columnDefs: [
+ {
+ targets: [ 0 ],
+ searchable: false
+ }
+ ]
+ } );
+
+ oTest.fnTest(
+ "Check html is stripped from second column",
+ function () { $('#example').dataTable().fnFilter('http'); },
+ function () { return $('div.dataTables_info').html() ==
+ 'Showing 0 to 0 of 0 entries (filtered from 4 total entries)';
+ }
+ );
+
+ oTest.fnTest(
+ "But can filter on text in links",
+ function () { $('#example').dataTable().fnFilter('Integrity'); },
+ function () { return $('div.dataTables_info').html() ==
+ 'Showing 1 to 3 of 3 entries (filtered from 4 total entries)';
+ }
+ );
+
+ oTest.fnTest(
+ "And on non-link text",
+ function () { $('#example').dataTable().fnFilter('EInt'); },
+ function () { return $('div.dataTables_info').html() ==
+ 'Showing 1 to 1 of 1 entries (filtered from 4 total entries)';
+ }
+ );
+
+ oTest.fnTest(
+ "No search results on non-serachable data (first column)",
+ function () { $('#example').dataTable().fnFilter('2'); },
+ function () { return $('div.dataTables_info').html() ==
+ 'Showing 0 to 0 of 0 entries (filtered from 4 total entries)';
+ }
+ );
+
+ oTest.fnTest(
+ "Release search",
+ function () { $('#example').dataTable().fnFilter(''); },
+ function () { return $('div.dataTables_info').html() ==
+ 'Showing 1 to 4 of 4 entries';
+ }
+ );
+
+
+ oTest.fnComplete();
+} );

0 comments on commit f3ce2e2

Please sign in to comment.