[SOLVED] Type based column filtering not working? Img alt filter/sort.
[SOLVED] Type based column filtering not working? Img alt filter/sort.
Hello all,
Loving dataTables thus far, but just one problem I've run into...
I have a column of 'status' images styled as:
[code]
[/code]
The column has a sType of 'alt-status' and I've added a custom sort to the column to sort them based on whether the alt text is red, yellow, or green. It works perfect and as expected. Here's that code:
[code]
jQuery.extend( jQuery.fn.dataTableExt.oSort, {
"alt-status-pre": function ( a ) {
switch(a.match(/alt="(.*?)"/)[1].toLowerCase()){
case 'green': return 1;
case 'yellow': return 2;
case 'red': return 3;
default: return 4;
}
},
"alt-status-asc": function( a, b ) {
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
},
"alt-status-desc": function(a,b) {
return ((a < b) ? 1 : ((a > b) ? -1 : 0));
}
} );
[/code]
Now, I would like to only filter them based on this alt field as well. I tried a few different things but none of them work. I tried:
[code]
$.fn.dataTableExt.ofnSearch['alt-status'] = function ( sData ) {
console.log(sData);
return sData.replace(/\n/g," ").replace( /<.*?>/g, "" );
};
[/code]
just to try and remove the html from the filter, but that didnt work either. I can still search for "
Loving dataTables thus far, but just one problem I've run into...
I have a column of 'status' images styled as:
[code]
[/code]
The column has a sType of 'alt-status' and I've added a custom sort to the column to sort them based on whether the alt text is red, yellow, or green. It works perfect and as expected. Here's that code:
[code]
jQuery.extend( jQuery.fn.dataTableExt.oSort, {
"alt-status-pre": function ( a ) {
switch(a.match(/alt="(.*?)"/)[1].toLowerCase()){
case 'green': return 1;
case 'yellow': return 2;
case 'red': return 3;
default: return 4;
}
},
"alt-status-asc": function( a, b ) {
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
},
"alt-status-desc": function(a,b) {
return ((a < b) ? 1 : ((a > b) ? -1 : 0));
}
} );
[/code]
Now, I would like to only filter them based on this alt field as well. I tried a few different things but none of them work. I tried:
[code]
$.fn.dataTableExt.ofnSearch['alt-status'] = function ( sData ) {
console.log(sData);
return sData.replace(/\n/g," ").replace( /<.*?>/g, "" );
};
[/code]
just to try and remove the html from the filter, but that didnt work either. I can still search for "
This discussion has been closed.
Replies
@bEEf732 mData just read data from JSON data source, but my datatable is initial from html table markup
Cheers!