and fnSetColumnVis
and fnSetColumnVis
moomanchoo
Posts: 2Questions: 0Answers: 0
Hi there,
I spent the past couple of days looking through the forums before posting, but haven't been able to sort my problem. Essentially I have table which uses to group some columns and have been attempted to use fnSetColumnVis to toggle the columns. Now I understand that this support is new in 1.8 and based on this thread here:
http://www.datatables.net/forums/discussion/4795/column-grouping-and-dynamical-column-hiding-dont-get-along/p1
it sounds like it should work (I'm using 1.8.1 and have also tried the latest nightly dev), but no luck.
So I have the following:
[code]
$(document).ready(function() {
$('#position_list').dataTable( {
"aaSorting": [[ 1, "asc" ],[2, "asc"]],
} );
} );
function fnShowHide( iCol ) {
/* Get the DataTables object again - this is not a recreation, just a get of the object */
var oTable = $('#position_list').dataTable();
var bVis = oTable.fnSettings().aoColumns[iCol].bVisible;
oTable.fnSetColumnVis( iCol, bVis ? false : true );
}
ID
Status
Ticker
Entry Details
Exit Details
Opened
Qty
Entry Price
Total Entry
Stop Loss
Exit Date
Exit Qty
Exit Price
Actions
Toggle column 1
[/code]
With the function call fnShowHide(x) I've tried every number between 1 and 12 and can only ever hide a single column. I am missing something very simple or am simply trying to do something this is not supported. I note that under the API section for fnSetColumnVis its not supported, but this seems to be different to whats in the above listed thread.
Also can I instead achieve the same end using the ColVis extra?
I spent the past couple of days looking through the forums before posting, but haven't been able to sort my problem. Essentially I have table which uses to group some columns and have been attempted to use fnSetColumnVis to toggle the columns. Now I understand that this support is new in 1.8 and based on this thread here:
http://www.datatables.net/forums/discussion/4795/column-grouping-and-dynamical-column-hiding-dont-get-along/p1
it sounds like it should work (I'm using 1.8.1 and have also tried the latest nightly dev), but no luck.
So I have the following:
[code]
$(document).ready(function() {
$('#position_list').dataTable( {
"aaSorting": [[ 1, "asc" ],[2, "asc"]],
} );
} );
function fnShowHide( iCol ) {
/* Get the DataTables object again - this is not a recreation, just a get of the object */
var oTable = $('#position_list').dataTable();
var bVis = oTable.fnSettings().aoColumns[iCol].bVisible;
oTable.fnSetColumnVis( iCol, bVis ? false : true );
}
ID
Status
Ticker
Entry Details
Exit Details
Opened
Qty
Entry Price
Total Entry
Stop Loss
Exit Date
Exit Qty
Exit Price
Actions
Toggle column 1
[/code]
With the function call fnShowHide(x) I've tried every number between 1 and 12 and can only ever hide a single column. I am missing something very simple or am simply trying to do something this is not supported. I note that under the API section for fnSetColumnVis its not supported, but this seems to be different to whats in the above listed thread.
Also can I instead achieve the same end using the ColVis extra?
This discussion has been closed.
Replies
Beautifully simple, I can't believe that didn't occur to me, I must be losing my grip!
I'll code it and give it go and let you know what happends.