Skip to main content
March 3, 2009
Answered

dynamically building up object array to populate a datagrid

  • March 3, 2009
  • 5 replies
  • 776 views
I am having a difficult time understanding how to push an object to an array to populate a datagrid.
I am not sure if I am not retrieving the values right or sending them.

I want to Push the full string as the label and on : "Data_Grid.selectedItem " retrieve the value by name with "Data_Grid.selectedItem.G_val" by dynamically building up the "type":"Value".




This topic has been closed for replies.
Correct answer
thank you :)

5 replies

kglad
Community Expert
Community Expert
March 5, 2009
you're welcome.

(and my 2nd sentence isn't quite correct. the objects don't need to have the same properties. but if you want to display all their properties, there should be a column for each property used.)
March 5, 2009
The project might be something you are intrested in after viewing the examples on your website.

Its a CAD to Flash viewer

http://www.cncscreens.com/GWI/GWI.html

Mouse wheel: zoom
Left click: pan

Yes the object is dynamicaly populating with the column name and value and then pushed to the dataprovider but...only if INDEX 0 has all of the column labels.

So like you said I have to dp.unshift({A:'', B:'', C:''}); to have the values pupulate the columns....but this means I have to keep tabs on the array and figure out all of the column names then "shift" them in to index0.

Since I am loading hundred thousand lines of code in the array I am trying to keep things running as fast as I can, this just added to the load time and complexity.

Example:

Index 0

Column: A B
Value: 1 1

Index 1 !!! this will not work since C wasnt in Index 0

Column: A B C
Value: 2 2 2

I have to "shift" Column: A B C

Basicaly I am bringing in X,Y,Z values but z might be in the middle of the file or not there at all if it is a 2d object.
Other elements to the file might need to be stored and display and vary on the CAD file or type. So it is hard to have a set colum names and values.
kglad
Community Expert
Community Expert
March 4, 2009
the dataprovider is an array of objects. each element of the array corresponds to a row in the datagrid.

all the objects should have the same properties which correspond to the columns of the datagrid.

you can add datagrid columns at any time using the addColumn() and addColumnAt() methods.
Correct answer
March 5, 2009
thank you :)
kglad
Community Expert
Community Expert
March 4, 2009
that's the general idea. datagrids generally have header or column values that explain the content type of each row.

you can't however push an ill-defined creation like {Info:myInfo},Obj

try:

March 4, 2009
Thank you KGlad that seems to work well!

However if I do not declare all of the colums in the first index and try to add colums later in the array they are not created.

Example :

index 0 sends: { G: "1" , Y: "1" }
index 1 sends: { H: "2" , X: "2" }

The dataProvider for the dataGrid only creates index 0 :colums |G| |Y| and does not add index 1 : colums |H| |X|
If in the first index I send every colum name they will be populated late, However I will not know till the end of the array how many colums and there names till the end of the loop.

Is there a good way to dynamicaly create colums on the fly or a better way then using an object and the dataprovider?

Currently I am using : dp.unshift({G_val:'', X_val:'', Y_val:''});
but would rather not.

March 3, 2009
Hi Kglad,
thank you for the reply.

If I do that it will fill the colum with the types name and the cell with the value.

I would like to display in one colum in 1 row:
for examlpe:

G1 X0.1031 Y-0.0416

but when the user click on it retrive each value:

Data_Grid.selectedItem.G_val

which would equal: 1

I am not sure how to display a "label" with multiple values behide it...out of site of the user?
kglad
Community Expert
Community Expert
March 3, 2009
:

dp.push(Obj);