PDA

View Full Version : Composite keys in Grid columns



Nagadev
30 Aug 2009, 8:46 AM
Hello,

My requirement is to have two primary keys (composite key) as columns in the Grid. So when I try to Edit the grid, it has to send composite key values to server along with the other modified columns. is that possible to specify two or more columns as part of id.

Thanks in advance.

jay@moduscreate.com
15 Sep 2009, 4:58 AM
why not create and split the composite key on the server side??

aconran
15 Sep 2009, 6:46 AM
Jay's suggestion of using a concatenated key to represent a composite key is probably the easiest and quickest route to go down if you need to get this done quickly.

Such as:


13980824:9209802

Where the colon delimits the two keys to form a composite key. The other alternative would be to implement a getId method on the Ext.data.Record object and instead of accessing .id directly throughout our internal framework code to access the getId method.

The other hurdle that would need to be jumped over would be adding functionality to the readers to be able to interpret composite keys and to know where to retrieve the individual keys from within the data that is loaded. Currently we do this through idProperty which can point to a simple value:



idProperty: 'productId',


This could be something like:


idProperty: {
primary: 'productId',
secondary: 'regionId'
}


All and all I'd say this would be a lot of work to get the functionality that you are looking for. I'd suggest going the route of concatenating the keys into a single composite value on the server-side and then use the reader to split the value into the appropriate fields.

jay@moduscreate.com
15 Sep 2009, 6:57 AM
Another approach to do it on the front end might be:

- upon the store's load event,
- loop through the data, concatenating the keys into a single id field.

Nagadev
25 Sep 2009, 1:34 AM
Thankyou both for your valuable suggestions, I will try concatenating upon store's load event