PDA

View Full Version : Associative arrays instead of indexed arrays


byuva
10-06-2006, 02:21 PM
At a conceptual level I am struggling with the positional nature of the data model. I like the recent change to add a "dataIndex" parameter to the column model but wonder if we could take it a step further.

cm = new YAHOO.ext.grid.DefaultColumnModel([{
header: "Common Name",
width: 155,
dataIndex: "name"
}]);

I like to view data in a SQL or object oriented perspective where a row/object has named attributes and types. Viewing the attributes as ordered or positional seems to create a potential maintenance nightmare (what happens if you remove a column, not only do you have to change all references to it but you have to decrement all numbered refences above it).

My naive solutions to add two private associative arrays to the abstract data model (or default?). We can still store the data the same way (no point in making an array of associative arrays) but create a lookup that simply maps each field name to its positional column. If no field names are passed to the constructor we can simply associate the column number <int> with the corresponding column (ie all of our methods that have been taking <int> should still work the same now that they take <hashable>). I also think another array that would associate each column with a type <string> would be helpful. The column model could use this to default sort, render and edit behavior.

Does this make sense? Are there advantages to using <int> access to the data?

-brian

jack.slocum
10-07-2006, 01:07 AM
I agree 100% and have come up with a similar solution. It will be in the .33 release.

Jack

glassy
11-24-2006, 11:47 AM
I'd like to add my vote for this feature request :wink:

From what I've looked at the code, I don't think it's in 0.33 RC2 yet.
Any plans?

BTW awesome work in 0.33 RC2 Jack!

jack.slocum
11-24-2006, 11:51 AM
This this got pushed off the list somehow. There was a solution I was working on but I got sidetracked. I have added it to the list again. :)

byuva
12-04-2006, 11:14 AM
It looks like some great stuff made it into .33 but I am a bit sad to see this was not included. Keeping column references independent of column order really makes user code a lot more maintainable (especially adding a column anywhere other than the end of the grid). Glad to see it is back on the radar and of course thanks again for all your hard work.

-b