FixedHeader + fnSetColumnVis?
FixedHeader + fnSetColumnVis?
shaneisme
Posts: 11Questions: 0Answers: 0
Hey all - I've got a very large table and need a way to hide columns.
I'm running the following options:
[code]
var oTable = $('#compare').dataTable({
"bInfo": false,
"bPaginate": false,
"bLengthChange": false
});
new FixedHeader( oTable, { "left": true} );
[/code]
I'm using the code in the following example: http://www.datatables.net/examples/api/show_hide.html
[code]
function fnShowHide( iCol )
{
/* Get the DataTables object again - this is not a recreation, just a get of the object */
var oTable = $('#compare').dataTable();
var bVis = oTable.fnSettings().aoColumns[iCol].bVisible;
oTable.fnSetColumnVis( iCol, bVis ? false : true );
}
[/code]
And, if I add the following to an anchor:
[code]onclick="fnShowHide(2);"[/code]
...nothing at all happens.
Using the search function works perfectly, as does sort.
I'm using jQuery 1.8.2.
Is there another way I need to do this using FixedHeader? Or is there probably something else I'm doing wrong?
I'm running the following options:
[code]
var oTable = $('#compare').dataTable({
"bInfo": false,
"bPaginate": false,
"bLengthChange": false
});
new FixedHeader( oTable, { "left": true} );
[/code]
I'm using the code in the following example: http://www.datatables.net/examples/api/show_hide.html
[code]
function fnShowHide( iCol )
{
/* Get the DataTables object again - this is not a recreation, just a get of the object */
var oTable = $('#compare').dataTable();
var bVis = oTable.fnSettings().aoColumns[iCol].bVisible;
oTable.fnSetColumnVis( iCol, bVis ? false : true );
}
[/code]
And, if I add the following to an anchor:
[code]onclick="fnShowHide(2);"[/code]
...nothing at all happens.
Using the search function works perfectly, as does sort.
I'm using jQuery 1.8.2.
Is there another way I need to do this using FixedHeader? Or is there probably something else I'm doing wrong?
This discussion has been closed.
Replies
Allan
http://promos.asus.com/us/z87/comparison/branch.1.1.0.asp
Pardon the mess, this is just a proof of concept :)
[code]
(function(event) { fnShowHide(1);
})
[/code]
fnShowHide is undefined.
Was that error present with the old version as well? Have you defined that function anywhere?
Not sure what is causing the misalignment - I'll try to look into it.
Allan
Perhaps there's a scope issue in there somewhere? I'll dig as well.
Edit - it was a scope issue! But now the column is hiding correctly, however the FixedHeader column is not.
Edit 2 - Switching back to 2.0.6 on FixedHeader works as intended, but it doesn't seem to remember the width.
Edit 3 - Using:
[code]
"bAutoWidth": false
[/code]
Solves this problem.
So basically, not using the nightlies I'm working fine :)
If you'd like me to test another version please feel free, it's the least I could do.
If I start the off hidden upon DOM load, the left column is rendered correctly. If I ask for the table to be re-drawn I lose all the filters I put in place by hiding columns.
Is there an example that you can think of I can use to basically provide the exact same functionality you've helped me do for columns for rows as well? Basically, on click of an anchor separate from the row itself, the row[id] hides.
Edit - never mind, I see FixedHeader brings with it any classes, so I'll just do that to call everything.
(I should post 5 minutes after I think I have a question from now on...)
[code]
Toggle
[/code]
JS:
[code]
function hideRow(classname) {
if ($(classname).is(':visible')) {
$(classname).css('display','none');
} else {
$(classname).css('display','table-row');
}
}
[/code]
As of right now, I declare the width of the parent, and then I use some basic math to add or subtract pixels from the parent.
My problem is when showing a column again using fnSetColumnVis, I can't seem to get the width of the column that's hidden... instead I get the column width next to it when I do something like this:
[code]
var width = $('#compare th').eq(iCol).width();
[/code]
I tried moving it after the fnSetColumnVis call, but it doesn't seem to work no matter what I do.
Is there a built-in function to keep track of the columns hidden by fnSetColumnVis?
Is there a simpler solution for me in general (am I doing things the hard way)?
Current version: http://promos.asus.com/us/z87/comparison/branch.1.2.0.asp
Is this information already stored in an array when data tables is called? If so, I can use that instead of taking up more memory with my array.