Hidden/shown columns depending on whether user is logged in or not...
Hidden/shown columns depending on whether user is logged in or not...
I have added this little block to hide/show columns with class "admin_only" (which is set during the page render)
[code]
if ($("th.admin_only").length > 0)
{
$("th").each(function(index) {
if ($(this).hasClass('admin_only'))
{
oTable.fnSetColumnVis(index,false);
}
else
{
oTable.fnSetColumnVis(index,true);
}
});
}
[/code]
unfortunately - once a column is hidden - it's always hidden, in fact it disappears from the dom during table instantiation before this code executes. If i delete the cookie, i can see it again. So... how can get this to work? Is this a bug or intended behaviour?
thanks!
Brad
[code]
if ($("th.admin_only").length > 0)
{
$("th").each(function(index) {
if ($(this).hasClass('admin_only'))
{
oTable.fnSetColumnVis(index,false);
}
else
{
oTable.fnSetColumnVis(index,true);
}
});
}
[/code]
unfortunately - once a column is hidden - it's always hidden, in fact it disappears from the dom during table instantiation before this code executes. If i delete the cookie, i can see it again. So... how can get this to work? Is this a bug or intended behaviour?
thanks!
Brad
This discussion has been closed.
Replies
It's a little complicated to explain by words... Experimentation is the way to go :-). One thing you can do is loop over fnSettings().aoColumns - this is an array of objects (which doesn't have it's length change on visibility!). Each object has a parameter called 'nTh' which will be the one you are interested in. This is probably the best way to go about doing what you are looking for.
Hope this helps!
Allan
this worked nicely.
[code]
jQuery.each(oTable.fnSettings().aoColumns, function(index, col) {
if ($(col['nTh']).hasClass('admin_only'))
{
oTable.fnSetColumnVis(index,false);
}
else
{
oTable.fnSetColumnVis(index,true);
}
});
[/code]