5

Anyone know how you model subfields of any field in ExtJS? For example

Ext.data.Model:

fields:[
   {name: 'id', type: 'int'},
   {name: 'title', type: 'string'},
   {name: 'description', type: 'string'},
   {name: 'priority', type: 'auto', fields:[
      {name: 'code', type: 'string'}
   ]},
   {name: 'createdBy', type: 'auto'},
]

then in my grid panel

Ext.grid.Panel

columns:[
    {header:'Title', dataIndex:'title', flex:1},
    {header:'Priority', dataIndex:'code'}
],

Any idea how I access the dataIndex 'code' under 'priority'? thanks in advance!

sha
  • 17,824
  • 5
  • 63
  • 98
Stevanicus
  • 7,561
  • 9
  • 49
  • 70
  • Here you can see my example to a similar question: http://stackoverflow.com/a/12694550/1496088 – DShost Oct 02 '12 at 16:55

2 Answers2

11

Thanks to @sha - here is the answer I needed :)

Model

fields:[

            {name: 'id', type: 'int'},
            {name: 'title', type: 'string'},
            {name: 'description', type: 'string'},
            {name: 'priority', type: 'auto'},
            {name: 'code', type: 'string', mapping:'priority.code'},
            {name: 'createdBy', type: 'auto'},

        ]

Gird Panel

columns:[

             {header:'Title', dataIndex:'title', flex:1},
             {header:'Description', dataIndex:'description'},
             {header:'Priority', dataIndex:'code'}

         ],
Stevanicus
  • 7,561
  • 9
  • 49
  • 70
4

Try this:

dataIndex: 'priority.code'
sha
  • 17,824
  • 5
  • 63
  • 98
  • 3
    can you use `mapping` feature of the Model to get scalar field from the nested information from your JSON/XML data source? – sha May 08 '12 at 16:05
  • thanks for that... mapping is key once again... poorly documented :) – Stevanicus May 09 '12 at 07:19
  • 1
    this works also but just for records are not null. if priority is null, it try to get code field of null and it causes error. – efirat Mar 29 '13 at 16:58
  • @sha: it runs as I say it above, for my store, I used `mapping: 'relatedProductType.id'` to get rid off null exception. however, it still gives me `Cannot read property 'id' of null`. have you got any idea? – efirat Apr 01 '13 at 09:04