Add and Delete a row in Grid



please give me sample code to add/delete rows in the js-array that is used to create grid.

I want to add/delete rows and refresh the grid.

please give me sample code.

thanks for the anticipated cooperation

April 28,
Here is simple example:
function addRow(){
    var rowData = ["GGL", "Google, Inc", "9,999.999", "765.432", "10000"]
    obj.setRowProperty("count", myData.length);

obj.setAction("click", addRow);
Alex (ActiveWidgets)
May 4,
And with XML?
May 5,
It works fine, but when I add a row after sort, the new row appears in the midle of the grid and overwrites the values....
any ideas?
July 19,
Same problem...no answer...
July 22,
Please check this thread, you will get your answers with sample code.


BTW, I have not done XML one, so can't suggest you anything.

Sudhaker Raj
July 23,
delete row:

function removeRow(grid) {
var index = grid.getProperty("selection/index");
if (confirm("Você tem certeza que deseja excluir?")) {
returnVal = myData.splice(index,1);
grid.setRowProperty("count", myData.length);
//alert(" count -> "+obj.getRowProperty("count")+ " |=> Deleted Row: " + returnVal);
Marlon Domingos
July 27,
I'm a newbie. Here do I put these enhancment codes.
Jason Matthews
April 26,
how to delet a row from dynamically added table in jsp usin javascript
sunil yadav
September 29,
How to add row if u using csv/xml as data src.
October 6,
Am also looking for a way to add/remove rows while using a XML datasource. Is it possible?
Meindert Hoving
October 17,
After sorting, removing a row have problem.
November 10,
AW 2.0 b3 is supposed have the add/delete/update rows functionality for the AW.XML.Table.
Rick Villela
November 10,
can somebody post the whole coding for adding data into table? having some difficulties here.. please, anyone :)
November 21,
You need to add data to a table or the activewidgets grid.
Also tell me u want to load data from javascript
or through any middleware language like PHP
Ritesh Jagga
November 22,
i have been able to insert data dynamically through javascript, but now the case I need the first data that is inserted to be in row 1.. but instead if i add more row, the data will replace , like

1st data - hello
2nd data - bye

the order should be

row 1 - hello
row 2 - bye

but now its like

row 1 - bye
row 2 - hello.. and so on..
can anybody help me?
November 24,
if data is being inserted in reverse order then change the row indices ordering using
Grid.setRowIndices([10,9,8,7,6,.......]);//This is for v2.0
It will reorder the data being inserted.

But what i think, it is not the problem, You copy-paste ur code so that problem can be viewed in an expanded view :)
Ritesh Jagga
November 24,
var obj1 = new Active.Controls.Grid;
obj1.setRowProperty("count", 1);
obj1.setColumnProperty("count", 4);

obj1.setDataProperty("text", function(i, j){return data1[i][j]});
obj1.setColumnProperty("text", function(i){return columns1[i]});

function addRow(){

selTerms = document.form.selTerms.options[ document.form.selTerms.selectedIndex ].text
selCond = document.form.selConds.options[ document.form.selConds.selectedIndex ].text
txtValue = document.form.txtValue.value
chkbox = "<input type=checkbox name=checkbox onclick=javascript:alert(txt); value="+txt+">"

var rowData = [chkbox,selTerms, selCond, txtValue]
obj1.setRowProperty("count", data1.length);

//obj1.setAction("click", addRow);

function removeRow(obj1) {
var index = obj1.getProperty("selection/index");
if (confirm("Are you sure?")) {
returnVal = data1.splice(index,1);
obj1.setRowProperty("count", data1.length);
//alert(" count -> "+obj.getRowProperty("count")+ " |=> Deleted Row: " + returnVal);
November 24,

With b2, i dont think it is quite possible to manage with XML directly. So, i had to create the data array based on the table object:

    //	create ActiveWidgets data model - XML-based table
    var table = new AW.XML.Table;

    //	create ActiveWidgets Grid javascript object
    // var obj = new AW.UI.Grid;
    var obj = new AW.Grid.Extended;

  My.obj=obj; // Reference for later use

    //	provide data URL

    //	set rows XPath

    //	set columns XPath

  // copy the reference
  // we have copied the real method.. It's time to override the method
  // so that the call comes to us before and lets us process the data when ready

  	//	provide column labels

    var rows=table.getCount();
    if(rows && rows<100) obj.setVirtualMode(false);


    // I maintain local methods and properties in My to avoid any reference clashes
    My.data=My.parseTableTextToArray(table, GC.ColumnNodes.length, rows);
    // My.parseTableTextToArray is the one that does the trick of converting
    // table data to a 2D array - see below

    // node is an element reference from document.getElementById
    // Note that you can populate data only when the response method was called;

  table.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT"); // Always Expires

    //	start asyncronous data retrieval


  var a=[];
  for(var i=0; i<rows; i++){
    for(var j=0; j<cols; j++){
  return a;

Hope this helps!


Md. Sheriff, Drivestream
November 28,
A small correction.. it is My.data and not GC.data (this might mean obvious for a good js developer ;)

My.data=My.parseTableTextToArray(table, GC.ColumnNodes.length, rows);

Md. Sheriff, Drivestream
November 28,
When you delete row 3 then row 4 shifts down to take it's place. Now your indexes are all offset -1 and the trouble begins. To have to grid do the deleteing (2.0) you have to pre-sort the selection array in reverse numerical order. Here's the simplest code i could come up with.

// delete multiple selected rows
var a = gv.getSelectedRows().sort(function(a,b){return b-a;});
for ( i = 0; i < a.length; i++ ) {
gv.deleteRow( a[i] );
gv.setSelectedRows( [0] );
May 5,
Hi all,

I try to did this in version 1.0. But after I sort one column, I run this script. I got javascript error in the try block saying avdata is not an object or null. Can anyone help me?

sel is the selected indexes.

sel = sel.sort(function(a,b){return(a>b? -1 : (a==b? 0 : 1))});
for(i=0; i<sel.length; i++) {
avdata.splice(sel[i], 1);

avail.setSelectionProperty("values", new Array());

July 27,

This topic is archived.

See also:

Back to support forum