3.0.0

Data in all added rows is same

I am evaluating grid control. I need to populate rows in the grid dynamically. Initially I developed a sample and it is working fine. Same code (with some necessary modifications) I inserted in main project and it is giving me a problem. When I add a new row using "addRow" method, it does not get populated in grid control. "addRow" method is called in loop to fill grid completely. When loop is executed 5 - 6 times, 5 - 6 entries are added to grid at a time. When loop move forward after this, after each row added, data in all above rows becomes same as that in newly added row.

I was facing same problem while developing sample application. But I modified some code and the problem was solved. I donot remember now, what modification I was done.

Can anyone please help me solving this ?

My code is as follow :-

var objGrid = new AW.UI.Grid;
var dataRowArray = new Array();
var colnames = new Array(20);
var columnCount;

//ATTACH EVENTS TO OBJECT
objGrid.onRowAdded = function(row){setRowData(this);};

//FUNCTION DEFINITIONS
function initGridControl()
{
var num = new AW.Formats.Number;
num.setTextFormat("#,###.");
dataRowArray = new Array(columnCount);
//colnames = new Array(columnCount);

objGrid.setSize(850, 300);
objGrid.setId("Worklistview");
objGrid.setHeaderText(colnames);
objGrid.setCellFormat(num, 2);
objGrid.setColumnCount(columnCount);
objGrid.setRowCount(0);
objGrid.setRowHeight(25);
objGrid.setCellEditable(false);

//Set selecter column
objGrid.setSelectorVisible(false);
objGrid.setSelectorText("*");
objGrid.setSelectorWidth(28);
objGrid.setHeaderHeight(20);

//objGrid.setSelectionMode(true);
objGrid.setSelectionMode("single-row");
document.write(objGrid); //Display object on browser
objGrid.refresh();
}

function addRecord(recordData)
{
dataRowArray = recordData;
objGrid.addRow(objGrid.getRowCount());
}

function setRowData(newRowHandle)
{
try
{
//newRowHandle.setCellData(dataRowArray);
//newRowHandle.setCellText(dataRowArray, objGrid.getRowCount() - 1, newRowHandle);
newRowHandle.setCellText(dataRowArray, objGrid.getRowCount() - 1);
}
catch(e)
{
alert('Error : ' + e.description);
}
}
Amit Joshi
January 29,
I am evaluating grid control. I need to populate rows in the grid dynamically. Initially I developed a sample and it is working fine. Same code (with some necessary modifications) I inserted in main project and it is giving me a problem. When I add a new row using "addRow" method, it does not get populated in grid control. "addRow" method is called in loop to fill grid completely. When loop is executed 5 - 6 times, 5 - 6 entries are added to grid at a time. When loop move forward after this, after each row added, data in all above rows becomes same as that in newly added row.

I was facing same problem while developing sample application. But I modified some code and the problem was solved. I donot remember now, what modification I was done.

Can anyone please help me solving this ?

My code is as follow :-

var objGrid = new AW.UI.Grid;
var dataRowArray = new Array();
var colnames = new Array(20);
var columnCount;

//ATTACH EVENTS TO OBJECT
objGrid.onRowAdded = function(row){setRowData(this);};

//FUNCTION DEFINITIONS
function initGridControl()
{
var num = new AW.Formats.Number;
num.setTextFormat("#,###.");
dataRowArray = new Array(columnCount);
//colnames = new Array(columnCount);

objGrid.setSize(850, 300);
objGrid.setId("Worklistview");
objGrid.setHeaderText(colnames);
objGrid.setCellFormat(num, 2);
objGrid.setColumnCount(columnCount);
objGrid.setRowCount(0);
objGrid.setRowHeight(25);
objGrid.setCellEditable(false);

//Set selecter column
objGrid.setSelectorVisible(false);
objGrid.setSelectorText("*");
objGrid.setSelectorWidth(28);
objGrid.setHeaderHeight(20);

//objGrid.setSelectionMode(true);
objGrid.setSelectionMode("single-row");
document.write(objGrid); //Display object on browser
objGrid.refresh();
}

function addRecord(recordData)
{
dataRowArray = recordData;
objGrid.addRow(objGrid.getRowCount());
}

function setRowData(newRowHandle)
{
try
{
//newRowHandle.setCellData(dataRowArray);
//newRowHandle.setCellText(dataRowArray, objGrid.getRowCount() - 1, newRowHandle);
newRowHandle.setCellText(dataRowArray, objGrid.getRowCount() - 1);
}
catch(e)
{
alert('Error : ' + e.description);
}
}
Amit Joshi
January 29,
My application need to add records in grid from database table.
To do so, I run through a loop and add one record in each iteration.
If I add records in such iterations, and sort the column by clicking on column header, above situation could be recreated.

PLEASE PROVIDE ME THE SOLUTION SOON

var objGrid = new AW.UI.Grid;
var dataRowArray = new Array();

//ATTACH EVENTS TO OBJECT
objGrid.onRowAdded = function(row){setRowData(this);};

//FUNCTION DEFINITIONS
function initGridControl()
{
    var FORMAT_NUMBER = new AW.Formats.Number;
    var FORMAT_STRING = new AW.Formats.String;
    var FORMAT_DATE = new AW.Formats.Date;
    var headerRowArray = ["Rank", "Country", "Internet users", "Data from", "Extension"];
    
    FORMAT_NUMBER.setTextFormat("#,###.##");
    FORMAT_DATE.setDataFormat("ISO8601");
    FORMAT_DATE.setTextFormat("dd-MMM-yyyy");
    
    objGrid.setSize(850, 550);
    objGrid.setId("workList");
    objGrid.setHeaderText(headerRowArray);
    objGrid.setCellFormat(FORMAT_NUMBER, 2);
    objGrid.setColumnCount(5);
    objGrid.setRowCount(0);
    objGrid.setRowHeight(25);
    objGrid.setCellEditable(false);
    
    //Set selecter column
    objGrid.setSelectorVisible(false);
    objGrid.setSelectorText("*");
    objGrid.setSelectorWidth(28);
    objGrid.setHeaderHeight(20);
    
    //objGrid.setSelectionMode(true);
    objGrid.setSelectionMode("single-row");
    document.write(objGrid); //Display object on browser
    objGrid.refresh();
}

function addRecordsDynamic()
{
    for(var i = 1; i <= 10; i++)
    {
        for(var j = 1; j <= 5; j++)
        {
            dataRowArray[j-1] = "Cell_" + i + "-" + j;
        }
        //alert(dataRowArray);
        objGrid.addRow(objGrid.getRowCount());
    }
}

function setRowData(newRowHandle)
{
    try
    {
        newRowHandle.setSelectedRows(objGrid.getRowCount() - 1);
        newRowHandle.setCellText(dataRowArray, objGrid.getRowCount() - 1);
    }
    catch(e)
    {
        alert('Error : ' + e.description);
    }
}
Amit Joshi
January 29,
The grid does not create a copy of the data but just keeps reference to the data array. Because you are using the same array object for all rows - all rows display the same data.
Alex (ActiveWidgets)
January 29,

This topic is archived.

See also:


Back to support forum

Search

Version 2

Looking for AW 2.6 ?
The old site is here.