Sorting with hidden columns to the left not working

Sorting with hidden columns to the left not working

nicsoftnicsoft Posts: 37Questions: 0Answers: 0
edited August 2012 in General
Using DT 1.9.3.

I'm trying to get sorting for some columns with select elements to work in my table. To the left of the columns I have a column that is hidden at initalization.

I am using the dom-select sorting plugin from DataTables.net:

[code]$.fn.dataTableExt.afnSortData['dom-select'] = function ( oSettings, iColumn )
{
console.log(iColumn);

var aData = [];
$( 'td:eq('+iColumn+') select', oSettings.oApi._fnGetTrNodes(oSettings) ).each( function () {
aData.push( $(this).val() );
} );
return aData;
};[/code]

When sorting one column, the index of the column is the same both when having and not a having hidden column to the left (iColumn in above afnSortData). But the sorting is applied on the column one step to the right when the the column to the left is hidden. If it is unhidden sorting works as supposed to.

How can I make sure that the sorting is applied to the same column which I am clicking when I have a hidden column to the left?

Replies

  • nicsoftnicsoft Posts: 37Questions: 0Answers: 0
    edited August 2012
    I did see this post: http://datatables.net/forums/discussion/5142/hidden-column-checkbox-column-sorting-bug/p1

    It states
    [quote] 1 $( 'td:eq('+iColumn+') input'

    It's counting the visible columns[/quote]

    Is that true anymore? I do get the same value of iColumn when trying to sort both with hidden as when sorting with unhidden column to the left? I also tried using Allans suggestion on the same post to use _fnColumnIndexToVisible, but than sorting is performed on the columns two steps to the right (which "make sense" since it's already sorting one step to the right when having a hidden column to the left).
  • nicsoftnicsoft Posts: 37Questions: 0Answers: 0
    edited August 2012
    This is the correct way of converting column index to visible index: iColumn = oSettings.oApi._fnColumnIndexToVisible( oSettings, iColumn );

    I tried iColumn = oTable.fnVisibleToColumnIndex( iColumn); which didn't work apparently.
  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    > I tried iColumn = oTable.fnColumnIndexToVisible( iColumn); which didn't work apparently.

    You need the fnColumnIndexToVisible plugin: http://datatables.net/plug-ins/api#fnColumnIndexToVisible

    Allan
  • nicsoftnicsoft Posts: 37Questions: 0Answers: 0
    edited August 2012
    Sorry, I made a mistake, updated my own answer. I actually tried fnVisibleToColumnIndex before not oTable.fnColumnIndexToVisible as I wrote before editing.

    As mentioned, this is how I do:

    [code]iColumn = oSettings.oApi._fnColumnIndexToVisible( oSettings, iColumn );[/code]

    Now at least it seems like the sorting is performed on the correct column. But I still have some problems...but that's another question: http://datatables.net/forums/discussion/11433/sort-entire-datatables-on-selected-text-in-columns-containing-select-elements-when-pagination-is-use
This discussion has been closed.