Custom Sort and bVisibile

Custom Sort and bVisibile

GathilasGathilas Posts: 3Questions: 0Answers: 0
edited January 2011 in General
I'm having a small problem with bVisible and a custom sort function. It seems that iColumn is sending the old column count from before the bVisible column was hidden. I've just hard coded the new column number into the sorting function as a temporary fix.

I'm not sure if this is a bug or if I'm doing something wrong.

Here is my code:

[code]/* Custom image sort by rel */
$.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]

[code]var oTable = $("#profile1").dataTable({
"aaSorting": [[ 2, "asc" ], [1, "asc"]],
"iDisplayLength": 25,
"sPaginationType": "full_numbers",
"aoColumns": [
{ "bVisible":false },
{ "sWidth": "16px", "sSortDataType": "dom-img" },
{ "sWidth": "125px" },
{ "sWidth": "198px" }
],
"bAutoWidth": false
});[/code]

Replies

  • allanallan Posts: 61,971Questions: 1Answers: 10,160 Site admin
    This is intentional - although potentially annoying when you what the visible index rather than the data index :-). DataTables has an internal function called _fnVisibleToColumnIndex which you can use (oSettings.oApi._fnVisibleToColumnIndex() ) to convert from a visible index to the data index. There is also an inverse function called _fnColumnIndexToVisible. It can get a little confusing at times working with hidden columns and column indexes :-)

    Allan
  • GathilasGathilas Posts: 3Questions: 0Answers: 0
    Thanks for such a quick response. I actually realized I was being a complete goof anyway and didn't need to use bVisisable since that removes the column all together and I needed the content in that column; just didn't need it visible.

    Gath
This discussion has been closed.