I'm writing a JavaScript web tool using Google Visualization API. One of the features I would like to have is the option of clicking in a column, and having a yes - no option. When yes is selected, then that particular column would be hidden. I added this listener, and this function to hide the column:
/* Define a table */
var table = new google.visualization.ChartWrapper({
'chartType': 'Table',
'containerId': 'chart2',
'options': {
'sortColumn': '-1',
'allowHtml' : 'true',
},
'style' : {
'white-space' : 'nowrap'
}
});
google.visualization.events.addListener(table, 'select',
function (){
var tablewrapper = table.getChart();
//var columnId = tablewrapper.getColumnDescriptions();
//console.log(tablewrapper);
/*var columnIndex = tablewrapper.getViewColumnIndex(); */
var selection = tablewrapper.getSelection();
for(var i = 0; i < selection.length; i++){
var item = selection[i];
console.log('{row:' + item.row + ',column:' + item.column + '}');
}
}
);
function hideColumn(columnIndex){
$('#chart2 td:nth-child(' + (columnIndex+1) + ')').hide();
return;
}
However, ev
does not have a property called column
, which may refer to the column index. Does someone know how can I do that trick, and if I'm missing something? Thanks!
Maybe you're in need of a Dataview ? You can use the hideColums() method to hide specified columns.
A read-only view of an underlying DataTable. A DataView allows selection of only a subset of the columns and/or rows. It also allows reordering columns/rows, and duplicating columns/rows.
A view is a live window on the underlying DataTable...
EDIT getSelection() would be a better fit to your question I guess.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.