1
0
mirror of https://github.com/DataTables/DataTables.git synced 2024-12-01 13:24:10 +01:00

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

This commit is contained in:
Allan Jardine 2013-02-16 11:27:41 +00:00
parent d5fb56ff37
commit f3ce2e2d44
3 changed files with 84 additions and 4 deletions

View File

@ -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(' ');

View File

@ -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(' ');

View File

@ -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();
} );