Sorting with hidden columns to the left not working
Sorting with hidden columns to the left not working
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?
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?
This discussion has been closed.
Replies
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).
I tried iColumn = oTable.fnVisibleToColumnIndex( iColumn); which didn't work apparently.
You need the fnColumnIndexToVisible plugin: http://datatables.net/plug-ins/api#fnColumnIndexToVisible
Allan
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