:: Forum >>

Getting dynamically created grid object

I have dynamically created several grids with various data. Each has its own Id. I need to be able to check the selectedindex of any/all of the grids but in order to do that I need to be able to get the grid object by id.

How can I do that? document.getElementById('mygrid') doesn't seem to work, or am I barking up the wrong tree?
Josh H.
Friday, January 20, 2006
the way I do it is:

eval('mygrid').anyOfTheActiveWidgetPropertiesOrMethodsHere

You can use a variable or a static string inside the eval parameter to get a handle to the actual grid, then you can do anything you would normally do to the grid. You can also place that handle into a variable like this:

x = eval('mygrid')
theIndex = x.getSelectedIndex();
theId = x.getId();
Jim Hunter
Friday, January 20, 2006
Josh, with the exception of a few specialized needs, eval() is code smell :) at least you shouldn't have to resort to it in this case. could you post your code responsible for creating grid objects?
dmb
Friday, January 20, 2006
And this is one of those cases. If the only link you have to a dynamically created grid is a variable with the grid name, this is about the only way to get a handle to it. Can you provide another, non-smelling, way to do it? If so, I would like to know so I can remove some odor from my code. I will be the first to admit that it is a very slow way to do things, but in some instances there is no other way, that's why it's provided for our use.
Jim Hunter
Friday, January 20, 2006
i think i can, i just need to see the code, that's why I asked Josh for a sample :)

Dmitry
Friday, January 20, 2006
and I'm sorry about the "code smell" remark. For some reason I thought Josh was also using eval in his code. my bad.
Dmitry
Friday, January 20, 2006
Don't worry about the comment, I am very familiar with it. I do a lot of refactoring and know the term "smell" and what it means. :)
Jim Hunter
Friday, January 20, 2006
In version 1 you can obtain reference to the grid js object from Active.System.all array -

var obj = Active.System.all['mygrid']
Alex (ActiveWidgets)
Friday, January 20, 2006
That is great to know Alex! I will have to update my code to remove the eval() as I know it's a slow method to use.

I am going to assume for now that AW.System.all will work the same for version 2. Is this correct?
Jim Hunter
Friday, January 20, 2006
In 2.0 you can use function

var obj = AW.object(id);
Alex (ActiveWidgets)
Friday, January 20, 2006

This topic is archived.


Back to support forum

Forum search