[SOLVED] Type based column filtering not working? Img alt filter/sort.

[SOLVED] Type based column filtering not working? Img alt filter/sort.

bEEf732bEEf732 Posts: 6Questions: 0Answers: 0
edited August 2012 in General
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 "

Replies

  • bEEf732bEEf732 Posts: 6Questions: 0Answers: 0
    The correct way to do this is now to use mData rather than ofnSearch. See: http://datatables.net/usage/columns#mData
  • xsbearxsbear Posts: 3Questions: 0Answers: 0
    I also have this problem, ofnSearch doesn't work!
    @bEEf732 mData just read data from JSON data source, but my datatable is initial from html table markup
  • xsbearxsbear Posts: 3Questions: 0Answers: 0
    Sorry , I just used mRender for my strip tag filter, it's ok!
  • bEEf732bEEf732 Posts: 6Questions: 0Answers: 0
    @xsbear mData has a multitude of uses. One of which, as you stated, is for reading data from data source. Another (and you can check out this example in the reference example code) is to apply settings, sorting, and filtering functionality.

    Cheers!
This discussion has been closed.