Sorting on images
Sorting on images
I have a table that uses images to display a RAG status (Red, Amber, Green) of the entry.
I have put in an alt value, and used a number for that alt value, but don't seem to be able to sort or serach correctly on that value, or indeed the full source name of the image
any clues?
I have put in an alt value, and used a number for that alt value, but don't seem to be able to sort or serach correctly on that value, or indeed the full source name of the image
any clues?
This discussion has been closed.
Replies
Allan
Here is my code:
[code]$.fn.dataTableExt.afnSortData['dom-img'] = function ( oSettings, iColumn ) {
var aData = [];
$( 'td:eq('+iColumn+') img', oSettings.oApi._fnGetTrNodes(oSettings) ).each( function () {
aData.push( $(this).attr('rel') );
} );
return aData;
}[/code]
Thanks for the great work,
Gathilas
This is the code I use for sorting based on the src inside an image somewhere in the content.
If I am not wrong all you need to do is replace src with alt (or rel if this is what is wanted).
[code]$.fn.dataTableExt.oSort['image-asc'] = function(a,b)
13{
14 var imgSrcPatt=/\< *[img][^\>]*[src] *= *[\"\']{0,1}([^\"\'\ >]*)/i
15 var x = imgSrcPatt.exec(a);
16 if (x!=null && x.length>1)
17 x=x[1].toLowerCase();
18 else
19 x="";
20 var y = imgSrcPatt.exec(b);
21 if (y!=null && y.length>1)
22 y=y[1].toLowerCase();
23 else
24 y="";
25 return ((x < y) ? -1 : ((x > y) ? 1 : 0));
26}; [/code]