Remove row from DataTable?

5,421 views
Skip to first unread message

Burnt

unread,
Jun 20, 2008, 1:57:47 PM6/20/08
to Google Visualization API
Hi folks,

is it possible to remove a row from a data table, just like adding
one?

Cheers,
Bernd

VizGuy (Google)

unread,
Jun 24, 2008, 4:37:22 AM6/24/08
to Google Visualization API
There is no API method for this now, but we will add it soon

adam

unread,
Jul 17, 2008, 6:28:15 PM7/17/08
to Google Visualization API
if you're desperate, you can use this function, in the form data =
removeRow(data,[RowNumber]) -
---------------------------------------
function removeRow(dataSet,rowId) {
var newData = new google.visualization.DataTable();
newData.addRows(dataSet.getNumberOfRows()-1);
for(var c=0; c<dataSet.getNumberOfColumns(); c++){

newData.addColumn(dataSet.getColumnType(c),dataSet.getColumnLabel(c),dataSet.getColumnId(c));
}
var r =0;
for(var i=0; i<dataSet.getNumberOfRows(); i++) {
if(i!=rowId){
for(var j=0;j < dataSet.getNumberOfColumns();j++){

newData.setCell(r,j,dataSet.getValue(i,j),dataSet.getFormattedValue(i,j));
}
r++;
}
}
return newData;
}
---------------------------------------

i've tested it on a simple table, and it seems to work fine.

--adam--

adam

unread,
Jul 17, 2008, 9:06:22 PM7/17/08
to Google Visualization API
Scratch that!

Google has it built in now -

http://code.google.com/apis/visualization/documentation/reference.html#DataTable_removeRow

Nice stuff, hey?

--adam--
Reply all
Reply to author
Forward
0 new messages