Show/hide columns using Javascript
Here a little function I wrote today
This function needs the following prototype function:
Have fun and take care!
/**
* function toggleColumnVisibility(oDataGrid, iColumnNr)
*
* + shows/hides column in grid
*
* @param object oDataGrid ActiveWidgets grid object
* @param integer iColumnNr column nr of column to show/hide
*
* @returns nothing
**/
function toggleColumnVisibility(oDataGrid, iColumnNr)
{
/* init */
//get visible columns array
var aVisibibleColumns = oDataGrid.getColumnValues();
//get index of column to hide
var iHideIndex = aVisibibleColumns.indexOf(iColumnNr);
/* do something */
if (iHideIndex>=0)
{
/* column found, hide it *
aVisibibleColumns.splice(iHideIndex, 1);
oDataGrid.setColumnValues(aVisibibleColumns);
oDataGrid.refresh();
}
else
{
/* column not found, show it */
aVisibibleColumns.splice(0, 0, iColumnNr);
aVisibibleColumns.sort(function compareNumbers(a,b){return a - b;});
oDataGrid.setColumnValues(aVisibibleColumns);
oDataGrid.refresh();
}
}
This function needs the following prototype function:
/**
* Array.prototype.indexOf
*
* + adds indexOf functionality to JS Array objects
*
**/
Array.prototype.indexOf = function(obj)
{
for (var i = 0; i < this.length; i++)
{
if (this[i] == obj)
return i;
}
return -1;
}
Have fun and take care!
Rekcor
March 8,