3.2.0

Associative Aray

Hi there,

I would like to congradulate you guys for this great script.


I do have a problem however. I use a associative array for my data like so:

myData["15"] = [value1,value2];
myData["16"] = [value3,value4];

Where 15 and 16 are ids from the database. My problem is this
alert(myData); gives:
,,,,,,,,,,,,,,value1,value2,value3,value4

And when I display the data like this:
playerList.setCellText(myData);

I get empty rows from 0 to 14. Then the 15th and 16th row are populated.

How can I solve this, by keeping the custom rows?

Thankx,

Cris
Cris_co
January 29,
Edit:
...by keeping the custom row ids?
Cris_co
January 29,
If you use number for indexes I believe js interpreter will assign the array starting at 0 for you. Not sure a workaround. Maybe you should merge with your original array? It depends what you are trying to do.
Tony
January 29,
There is an example here -

http://www.activewidgets.com/javascript.forum.7911.13/server-side-filtering-ajax-style.html

you have to call setRowIndices([...]) method to specify which indices should be used for retrieving data from the associative array.
Alex (ActiveWidgets)
January 30,
Yup that's exactly what I did.

Wanted to post the method, but you beat me to it Alex.

Thankx for the replies.

Cris
Cris_co
January 31,
Here's the full code so people can cut and paste:

var myData = [];
myData["343"]= ["Pavel Datsyuk","3900000.0","DET","C","89"]

myData["385"]= ["Pat Leahy","450000.0","BOS","RW","68"]

myData["257"]= ["Keith Primeau","3420000.0","PHI","C","85"]

and about 700 other NHL players...

var myColumns = ["Name", "Salary", "NHL Team", "Position", "Overall"];

function getKeys(array){
var keys = [];
for (var key in myData){
keys.push(key);
}
return keys;
}


var playerList = new AW.UI.Grid;
playerList.setSize(800, 250);

playerList.setHeaderText(myColumns);

playerList.setColumnCount(5);
playerList.setRowCount(myData.length);

var showRowID = getKeys(myData);
playerList.setRowIndices(showRowID); // the IDs
playerList.setCellText(myData); // the data
playerList.setSelectionMode("single-row");
document.write(playerList);

******************************************************

Now if only I can get this piece of code to work:
var curency = new AW.Formats.Number;
curency.setTextFormat("#,###,###.#");
playerList.setCellFormat(curency, 1);

The column sorts as numbers (i.e 6 will be before 44) but it doesn't show the correct formating (i.e 3,900,000.0 for Datsyuk).

Any suggestions?
Cris_co
January 31,

This topic is archived.

See also:


Back to support forum