Please help me find a solution!


I'm trying to update a grid, i.e. Add a new line from fields on the form, using grid.Refresh() and I can't get it to work.

The code I have is follows:

<div id="barButtons">
<button id="btnAdd" onclick='addLineAJM()'>Add Line</button>
<button id="btnUpdate">Update Line</button>
<button id="btnRemove">Remove Line</button>
<button id="btnShowData" onclick='alert(lineData)'>Show Data</button>

<script type="text/javascript">
var lineData = [
var lineColumns = [
"Line Number", "Item Code", "Product Description", "Quantity", "Unit Price", "Amount", "UNID"
var gridLines = new Active.Controls.Grid;
gridLines.setId( "linesGrid" );
gridLines.setRowProperty( "count", lineData.length);
gridLines.setColumnProperty( "count", 7 );
gridLines.setDataProperty( "text", function( i, j ){return lineData[i][j] } );
gridLines.setColumnProperty( "text", function( i ){ return lineColumns[i] } );
gridLines.sort( 0, "ascending" );
document.write( gridLines );

function addLineAJM()
gridLines.setRowProperty("count", gridLines.getRowProperty("count") + 1);
lineData[lineData.length] = ["1", "1","1","1","1","1","1"];
gridLines.setDataProperty( "text", function( i, j ){return lineData[i][j] } );

As you can see, i've hard-coded the lines to be entered for the mean time, and when I click the "Show Data" button, the data has been added to the array ok (or I think it has).

i've tryed the following:

function addLineAJM()
rowData = ["1", "1","1","1","1","1","1"];
gridLines.setRowProperty("count", 2);

and the data in the first line changes, but the second line (with the original data) is not shown.

Again, the data is added to the array (at the front), but the line count doesn't seem to update.

Can someone point me in the right direction please?
August 25,
I have found that with many of the Array functions, you have to update the length of the array manually. I have done this sort of thing before and it worked:

lineData[lineData.length] = ["1", "1","1","1","1","1","1"];

Then the array length is accurate and the rest of your stuff should work. The grid only displays the number of rows you tell it to. So if the array has 10 rows but you are setting the rowcount of the grid to 4 (due to incorrect length values) then the grid will only show 4 rows. Check this out in your code, make sure that you are getting the correct length values where you are using them.
Jim Hunter
August 25,
try using this
function addLineAJM(){

var rowData = ["1", "1","1","1","1","1","1"];

gridLines.setRowProperty("count", lineData.length);


i hope that would do ....

August 26,
Found it!!!

The line --> gridLines.sort( 0, "ascending" ); was stopping it working!

August 26,

This topic is archived.

See also:

Back to support forum


Version 2

Looking for AW 2.6 ?
The old site is here.