:: Forum >>

Copy row from one grid to another...

Using ActiveWidgets 2.0.2 trial version running in IE7 or FF2.0.0.3

This is based on an example from the forums. The issue is that I can transfer items from left to right using >> but when I transfer them back using << a blank row is inserted.

Please any help with this as I am looking to buy this product but without an answer to this problem its a 'no go'. Thanks

Code stripped down to be just one page:
---------------------------------------------------------------<Head>
<script type="text/javascript" src="aw.js"></script>
<link href="aw.css" rel="stylesheet" />
</Head>

<Body>
<div id="AllCompanies"></div>
<a href="javascript: AddToPeerList();">>></a>
<a href="javascript: RemoveFromPeerList();"><<</a>
<div id="PeerList"></div>

<script type="text/javascript" language="javascript">

// Headers for the grid
var myHeaders = ["Company", "Value", "% Diff"];


// Create the source grid with the list of companies and thier data values
var AllCompanies = new AW.UI.Grid;
AllCompanies.setHeaderText(myHeaders);
AllCompanies.setColumnCount(3);

var AllCompaniesData = [
["Maytex Petro Inc", "1010.50", "-71.69"],
["Bastillion Energy Inc", "3205.95", "24.93"],
["<u>MyOilCompany</u>", "3570.00", "0"],
["JRC Petroleum Ltd", "4459.99", "24.93"],
["Wisdom Resources Inc", "55000.00", "54.06"]
];

// Set up first grid with data
AllCompanies.setCellText(AllCompaniesData);
AllCompanies.setRowCount(AllCompaniesData.length);
AllCompanies.setSelectionMode("multi-row");
AllCompanies.setId("AllCompanies");
AllCompanies.refresh();

// Create the blank destination grid that holds the current peer list
var PeerList = new AW.UI.Grid;
PeerList.setHeaderText(myHeaders);
PeerList.setColumnCount(3);

var PeerListData = [
["empty", "1000", "0"]
];

// Remove the dummy row we added
PeerList.setCellText(PeerListData);
PeerListData.splice(0,1);
PeerList.setRowCount(PeerListData.length);
PeerList.setSelectionMode("multi-row");
PeerList.setId("PeerList");
PeerList.refresh();

// Add a row
function addRow(rowData,grid,dataSrc)
{
dataSrc.unshift(rowData);
grid.setRowCount(dataSrc.length);
}

// Delete a row
function delRow(index,grid,dataSrc)
{
dataSrc.splice(index,1);
grid.setRowCount(dataSrc.length);
}

// Adds selected row (or rows) to the peerlist
function AddToPeerList()
{
selectedRows = AllCompanies.getSelectedRows();
selectedRows.sort();
AllCompanies.setSelectedRows([]);
for(iter in selectedRows)
{
index = selectedRows[iter];
rowData = AllCompaniesData[index];
addRow(rowData,PeerList,PeerListData);
}

selectedRows.reverse();
for(iter in selectedRows)
{
index = selectedRows[iter];
delRow(index,AllCompanies,AllCompaniesData);
}
AllCompanies.refresh();
PeerList.refresh();
}

// Removes selected row (or rows) from peerlist
function RemoveFromPeerList()
{
selectedRows = PeerList.getSelectedRows();
selectedRows.sort();
PeerList.setSelectedRows([]);
for(iter in selectedRows)
{
index = selectedRows[iter];
rowData = PeerList[index];
addRow(rowData,AllCompanies,AllCompaniesData);
}

selectedRows.reverse();
for(iter in selectedRows)
{
index = selectedRows[iter];
delRow(index,PeerList,PeerListData);
}
PeerList.refresh();
AllCompanies.refresh();
}

</script>
</body>
Joe Craig
Thursday, May 3, 2007
Maybe this example can help (it has two grids and two buttons to move rows between them) -

http://www.activewidgets.com/javascript.forum.13420.0/example-move-rows-between-two.html

The grids share the same data source and the code just manipulates the arrays of row indices in each grid.
Alex (ActiveWidgets)
Thursday, May 3, 2007
Alex

Thanks for the example I will give that a try and let you know if it fixes my disappearing row problem.
Joe Craig
Thursday, May 3, 2007

This topic is archived.


Back to support forum

Forum search