Hide/show column dynamic
Hide/show column dynamic
fernandogferreira
Posts: 7Questions: 0Answers: 0
Hey all,
I guess I have a simple task for implementing, but I've already spent 3 hours on it. I can't find anything useful on the web... Although I am sure you will be able to help me...
I've defined a dataTable object:
[code]
oTable = $('#main').dataTable({
"bSort": [
true,
true,
true,
true,
false,
true,
true,
false,
],
"aaSorting": [ [0,'asc'], [1,'asc'] ],
"aoColumns": [
null,
null,
null,
null,
{"bSortable":false},
{"bSortable":false, "bVisible":false},
{"bSortable":false},
{"bSortable":false, "bVisible":false},
{"bVisible":false},
{"bSortable":false},
],
"fnDrawCallback":function(){
redrawTable();
}
});
[/code]
As you can see I have a Draw callback functions that handles with all table designed and operations... That's work smoothly :D
I want to be able to toggle columns dynamic inside the function drawTable depending on certain conditions...
I know that I have to use the
[code]
$.fn
[/code]
The problem is I can't find the SetColumnVis() function....
Thanks in advance...
I guess I have a simple task for implementing, but I've already spent 3 hours on it. I can't find anything useful on the web... Although I am sure you will be able to help me...
I've defined a dataTable object:
[code]
oTable = $('#main').dataTable({
"bSort": [
true,
true,
true,
true,
false,
true,
true,
false,
],
"aaSorting": [ [0,'asc'], [1,'asc'] ],
"aoColumns": [
null,
null,
null,
null,
{"bSortable":false},
{"bSortable":false, "bVisible":false},
{"bSortable":false},
{"bSortable":false, "bVisible":false},
{"bVisible":false},
{"bSortable":false},
],
"fnDrawCallback":function(){
redrawTable();
}
});
[/code]
As you can see I have a Draw callback functions that handles with all table designed and operations... That's work smoothly :D
I want to be able to toggle columns dynamic inside the function drawTable depending on certain conditions...
I know that I have to use the
[code]
$.fn
[/code]
The problem is I can't find the SetColumnVis() function....
Thanks in advance...
This discussion has been closed.
Replies
fnSetColumnVis( columnIndex, false );
I've got my columns hiding and showing but I need to force a redraw of the datatable when it gets too narrow but something is topping fnDraw from working.
Can you send me a peace of code?
http://www.datatables.net/usage/callbacks
right now I have
[code]
"fnDrawCallback":function(){
redrawTable();
}
[/code]
And I would like to call SetColumnVis() inside it....
$('tableid').SetColumnVis does not work... I almost sure that is related to $.fn object... But I don't know where in the DOM tree I can find the target method.
Cheers
You seem to be making this harder than it has to be.
"fnDrawCallback":function(){
oTable.fnSetColumnVis( );
}
That should be the basic framework of what you need.
I have a fnDrawCallback function named redrawTable. Inside this function I do something like
[code]
$.post('checkIfUserIsLogged.php', {}, function(data){
if(data == 'OK'){
//The user is logged in to the system
//Here I'd like to show some columns that are hidden for a standard visitor
}
});
[/code]
As I've told before I created the dataTable object this way:
[code]
oTable = $('#main').dataTable({
"bSort": [
true,
true,
true,
true,
false,
true,
true,
false,
],
"aaSorting": [ [0,'asc'], [1,'asc'] ],
"aoColumns": [
null,
null,
null,
null,
{"bSortable":false},
{"bSortable":false, "bVisible":false},
{"bSortable":false},
{"bSortable":false, "bVisible":false},
{"bVisible":false},
{"bSortable":false},
],
"fnDrawCallback":function(){
redrawTable();
}
});
[/code]
oTable can't be seen inside the redrawTable. I've also tried pass $(this) to the function, but it haven't worked as well.
I guess, somehow, I could use $.fn for calling fnSetColumnVis(...)...
So, am I going to the wrong direction? Do you have any suggestion?
Example: http://datatables.net/examples/api/show_hide.html
Hopefully that will help.
Also I hope there isn't anything in redrawTable() which will actually redraw the table! Otherwise you'll get an endless loop. fnSetColumnVis does not redraw the table, it just does some DOM manipulation.
Regards,
Allan