Dynamically hide/show columns

Dynamically hide/show columns

haroldfharoldf Posts: 1Questions: 0Answers: 0
edited May 2013 in Plug-ins
I have a (fairly) wide table used for different purposes. Users can adjust their view (specifically which columns are shown) using ColumnVis, but there are some common situations which require the very different starting points. For example, for one task a user needs to view cols 1,2,3,4. For another: 1,31,32,36. And so on -- about six of them. The columns available change fairly often. Using servert-side processing and my current (flawed) procedure, maintenance involves changing the database then editing a config file to match: no programming required.

I am using server side processing to request not only the data but also, using fnServerParams, a view.

I am currently returning data which includes a top-level key 'visibility' and a keyed array of column names with values true (visible) or false. Something like this:
[code]
{"visibility":{"fieldname1":false,
"fieldname2":false, "fieldname3":true, "fieldname4":true, ...},
"iTotalDisplayRecords": "1400",
"iTotalRecords":"1400",
"aaData":[...],
"sEcho":"1"}[/code]
What I think I would like is to be able to do is set bVisible for each column in aoColumns, but I cannot work out how to do that.

What I am doing is in aoColumns, mData sets (among other things) sName and sets bVisible false for every column.

fnInitComplete re-parses the data from oSettings.jqXHR.responseText then iterates through visibility, and where true does tab.fnSetColumnVis(index, true);.
[code]
"fnInitComplete": function(oSettings, json) {
var data = $.parseJSON( oSettings.jqXHR.responseText );
var visibility = data.visibility;
$(oSettings.aoColumns).each (
function (index, value) {
if (visibility[value.sName]) {
tab.fnSetColumnVis(index, true);
}
}
);
}
[/code]
That works, sort of, but as you can imagine adds a tangible delay. I tried leaving the fnSetColumnVis redraw to false except on the last loop and that does not work.

How should this best be done?
This discussion has been closed.