Pick what columns to show
Pick what columns to show
I want to make my users able to pick what columns to show, and hide all others. You know like the icon to the right in most table-based software like Thunderbird/office.
I think I can solve it with hidden columns example, but just wanted to make sure that this function (or plugin) doesn't already exist?
I think I can solve it with hidden columns example, but just wanted to make sure that this function (or plugin) doesn't already exist?
This discussion has been closed.
Replies
There isn't a plug in as such, but a simple call to the API function from whatever UI widget you want to use will do the trick.
Allan
I have a checkbox with class toggleColumn for each column. This function is called whenever the box is changed:
[code]
function updateColumns()
{
$('input.toggleColumn').each(function() {
var col = $(this).val();
var show = $(this).is(":checked");
var bVis = oTable.fnSettings().aoColumns[col].bVisible;
if(show && !bVis)
oTable.fnSetColumnVis(col, true);
else if(!show && bVis)
oTable.fnSetColumnVis(col, false);
});
}
[/code]
This gives me error message "nTd is undefined"
[code]
var col = parseInt($(this).val());
[/code]
Allan
Could you post the checkbox (or select box? ) code as well?
Looking for exactly this.
cheers,
G
[code]
function updateColumns()
{
if($('table#example').length>0)
{
var colsToHide=new Array(20);
var cookiestr = "";
$('input.toggleColumn').each(function() {
var col = parseInt($(this).val());
var show = $(this).is(":checked");
if(show) cookiestr = cookiestr + col + ",";
oTable.fnSetColumnVis(col, show);
});
cookiestr = cookiestr.substr(0,(cookiestr.length-1));
var date = new Date();
date.setTime(date.getTime() + (3600 * 24 * 1000));
$.cookie("selectedcols", cookiestr, { path: '/', expires: date });
}
}
[/code]
[code]
Show/hide columns here.
Col1:
Col2:
Col3:
[/code]
[code]
Show / Hide Columns:
Service
Title
(Does not Work)
Show / Hide Columns2:
Service
Title
[/code]
HTML
[code]
Show / Hide Columns2:
Service
Title
[/code]
JS
[code]
function updateColumns()
{
if($('#MYTABLEID').length>0)
{
var colsToHide=new Array(20);
var cookiestr = "";
$('input.toggleColumn').each(function() {
var col = parseInt($(this).val());
var show = $(this).is(":checked");
if(show) cookiestr = cookiestr + col + ",";
oTable.fnSetColumnVis(col, show);
});
cookiestr = cookiestr.substr(0,(cookiestr.length-1));
var date = new Date();
date.setTime(date.getTime() + (3600 * 24 * 1000));
$.cookie("selectedcols", cookiestr, { path: '/', expires: date });
}
}
[/code]