:: Forum >>
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
Sunday, January 29, 2006
Edit:
...by keeping the custom row ids?
Cris_co
Sunday, January 29, 2006
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
Sunday, January 29, 2006
Alex (ActiveWidgets)
Monday, January 30, 2006
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
Tuesday, January 31, 2006
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
Tuesday, January 31, 2006
This topic is archived.
Back to support forum
Forum search