PDA

View Full Version : GridPanel Record ID Questions



kgmoney
6 Jun 2008, 8:25 AM
Hi,

I have a couple questions regarding the id on a record.

1) To define the id column for a store you use the following, correct?


var TableColumnRecord = Ext.data.Record.create([
{name: 'something'},
{name: 'name'},
{name: 'somethingelse'}
]);
var storeTableColumns = new Ext.data.Store({
reader: new Ext.data.ArrayReader({id: 1}, TableColumnRecord),
.....


2) Then if I storeTableColumns.add(...), shouldn't I be able to storeTableColumns.getById('somename') and get the associated record? Currently I can only get this to work if I load the data via storeTableColumns.loadData(...).

3) If I have some records in the store and edit the 'name' field on one of them (using a EditorGridPanel), shouldn't I be able to get that record using the storeTableColumns.getById('newname')?

Any insight would be much appreciated, thanks.

mjlecomte
6 Jun 2008, 9:25 AM
2. Sounds ok kind of. Why not post your code? Try probing via firebug to see if you are assigning the id correctly.

3. Maybe I misunderstood, but if you edit a cell in an editor grid panel you are not changing the record id, you are changing one of the field's values.

kgmoney
6 Jun 2008, 10:49 AM
Hi,

Thanks for the reply.

2) So the code would be like...


storeTableColumns.add(new TableColumnRecord({
something: 'col1data',
name: 'col2data',
somethingelse: 'col2data'
});
var record_I_Just_Added = storeTableColumns.getById('col2Data')


3) Ok, so the ID is set equal to the 'name' field when the record is added and then left alone? It's not really tied to the field? If this is the case can I set the record's ID manually after the record has been added to the store. So, in other words, I want to 'tie' the ID to the 'name' column...so when I edit the 'name' column, I manually set the ID to match.

What do you think?

devnull
6 Jun 2008, 12:18 PM
thats not really making sense to me at all... if you have any experience with relational databases, dataStores can be thought of as database tables. each row (record) in the database (store) needs a unique identifier of some sort so that you can tell one record from another.
The id should always be a static value, usually unrelated to the rest of the fields in the record, and normally never displayed or used by the user. fortunately databases (and dataStores) give you tools to find records based on search criteria, such as in your example a specific field containing the value 'somename'.

mjlecomte
6 Jun 2008, 1:25 PM
I don't know if you've seen it, but I have an example posted. You could probably just scan it over if nothing else. I documented it pretty thoroughly as I was learning it. In retrospect I would do things different....or I've learned to do things different....but some of the underlying principles are still valid and should be informative nonetheless. I had some confusion over "id" as well and I address this specifically. For example, don't confuse a field inside your record called "id" with the id of an instance of a record object (auto assigned by ext unless you do it).

kgmoney
6 Jun 2008, 1:37 PM
devnull:

Well, if that's how Ext works, I can work with it. However, going back to your relational db example, in the dbs I've worked with you can have any field be your key field (whether it's displayed/modified or not).

Your example does make me stop and think though, that really what I'm after is a unique field (I don't really care if it's the key or not), but this is something else I've not seen in my searching (which is why I started looking at the id). Can you have a unique constraint on a field/column (or multiple would be even better) in a store?


mjlecomte:

That sounds kind of familiar, that might be one of the posts I found. Do you recall what I might search for to find it?


Thanks guys

mjlecomte
6 Jun 2008, 1:40 PM
I dunno....maybe my signature? 8-|

In my example I specifically renamed "id" to "primaryKey" to eliminate some of the confusion between these two terms.

kgmoney
9 Jun 2008, 6:06 AM
Oh, you mean the bold one! :S

Anyway, after looking the example over, I don't think that quite addresses what I'm looking for. As mentioned above, what I'm really looking for is a unique contraint on a column or columns (maybe I should repost this since the question has changed a bit).

mjlecomte
9 Jun 2008, 4:25 PM
I don't think reposting is going to help any. You can edit your first post if you want to change the title (use advanced editing to do that).

Regardless I fail to see the difference, at least with a key on one column anyway, which is exactly what my example has.