Toggling multiple columns
Toggling multiple columns
I can show/hide one column by using this: http://www.datatables.net/examples/api/show_hide.html
But I need to toggle multiple columns of a table.
I have this table:
[code]
aaa
bbb
ccc
ddd
eee
fff
ggg
hhh
iii
jjj
[/code]
So I wrote this:
[code]
function showHide() {
var indices = [];
$("#myTable tbody tr").first().children("td.myclass").each(function(){
indices.push($(this).index());
});
var oTable = $("#myTable").dataTable();
for(var ind in indices)
{
var iCol = indices[ind];
var bVis = oTable.fnSettings().aoColumns[iCol].bVisible;
oTable.fnSetColumnVis( iCol, bVis ? false : true );
}
}[/code]
It works well first time I run showHide(). But when I run showHide() second time, it can't find the columns. It gives an empty "indices" array.
I tried ColVis. But it doesn't give me option to hide/show them by the class names of columns. It permits to hide/show one by one and by selecting the column name.
Is there a better solution for the multiple column toggling??
Thank you.
But I need to toggle multiple columns of a table.
I have this table:
[code]
aaa
bbb
ccc
ddd
eee
fff
ggg
hhh
iii
jjj
[/code]
So I wrote this:
[code]
function showHide() {
var indices = [];
$("#myTable tbody tr").first().children("td.myclass").each(function(){
indices.push($(this).index());
});
var oTable = $("#myTable").dataTable();
for(var ind in indices)
{
var iCol = indices[ind];
var bVis = oTable.fnSettings().aoColumns[iCol].bVisible;
oTable.fnSetColumnVis( iCol, bVis ? false : true );
}
}[/code]
It works well first time I run showHide(). But when I run showHide() second time, it can't find the columns. It gives an empty "indices" array.
I tried ColVis. But it doesn't give me option to hide/show them by the class names of columns. It permits to hide/show one by one and by selecting the column name.
Is there a better solution for the multiple column toggling??
Thank you.
This discussion has been closed.