PDA

View Full Version : Reusing the DataModel



dmayer
12 Oct 2006, 7:21 AM
I want to create an AJAX-based select control on on my web page that can be utilized by the yui-ext grid.

I already have figured out how to do this with a JS function, the Yahoo connection manager and yui-ext Dom Helper.

What I want to do now is create a resusable JS object that can be incorporated into the yui-ext library.

I was thinking about re-using the DataModels found in the grid. What I like about the DataModel is that is has a definable schema and methods to load JSON, XML,etc. The downside is that the DataModel to tightly coupled to the grid. Is there a way to separate the DataModel from the grid so it can be used in other types of control (E.g. a dynamic select box)?

Ideally, I would like to extend the DataModel schema so it has an ID field which could be bound to the ID of the option tag and a display column that would shown in the select box (the data would be placed between the option start and end tag).

Once the select control was available, it would be very easy to point the grid's selecteditor to it.

Any thoughts?

jack.slocum
12 Oct 2006, 7:36 AM
The data model is only coupled to the grid on the sort() method and that dependency is being removed in a future release. sortType should be on the data model, not the column model.

Other than that, the data model can be used for anything. In fact, in the form library I never get to work on, I'm planning on using the data model to do exactly what you said - bind a data model to a select field.

If you do create a select field bound to a data model, you can use the model's events to keep the select options in sync with the data model. That was the idea I had. So you call load() or sort or addRow and it updates the select field automatically, kinda like the grid works now.

You won't need to make any changes to the data model classes to support this. It will work right now.

dmayer
12 Oct 2006, 8:31 AM
In the future release. would the datamodel move up from

YAHOO.ext.grid.AbstractDataModel

to

YAHOO.ext.AbstractDataModel?

jack.slocum
12 Oct 2006, 9:32 AM
It will be:

YAHOO.ext.data.AbstractDataModel, YAHOO.ext.data.XMLDataModel, etc

The directory is already there in the source to prepare for it. I will probably provide an alias for the first couple releases so it doesn't break anyone's code.