0

So I've a problem 'cause i want to show parent data on grid, illustrated here:

PARENT MODEL

Ext.define('Ab.model.Marca', {
    extend: 'Ext.data.Model',
    fields: ['id','nombre'],
    hasMany: {model: 'Ab.model.Maquina', name: 'maquina'},
    proxy{...}
 });

CHILD MODEL

Ext.define('Ab.model.Maquina', {
    extend: 'Ext.data.Model',
    fields: ['id','nombre', 'codigo', 'estado'],
    associations: [
        {type:'belongsTo', model:'Ab.model.Marca', name: 'marca'},
    ]
    proxy:{...}
 });

CHILD GRID

Okay, MaquinaController execute load from Store and that is not important 'cause load informations very nice. The problem is that I can't show parent data.

Ext.define('Ab.view.maquina.MaquinaList', {
    extend: 'Ext.grid.Panel',
    alias: 'widget.maquinalist',
    store: 'Maquinas',
    columns: [
        { text: _('Nombre'), flex: 1, dataIndex: 'nombre' },
        { text: _('Código Externo'), flex: 1, dataIndex: 'codigo' },
        { text: _('Estado'), flex: 1, dataIndex: 'estado' },
        { text: _('Marca'), flex: 1, dataIndex: 'marca' }    <<< HOW CAN I SHOW MARCA?
    ]
});

Thanks in advance.

richardhell
  • 969
  • 2
  • 10
  • 22

1 Answers1

2

Override column.renderer , and return record.getParent().get('someData');

http://docs.sencha.com/ext-js/4-1/#!/api/Ext.grid.column.Column-cfg-renderer

renderer: function(value, metadata, record, rowIndex, colIndex, store, view){
  return record.getMarca().get('nombre');
}

Also, make sure you are following the rules:

http://extjs-tutorials.blogspot.ca/2012/05/extjs-belongsto-association-rules.html

Neil McGuigan
  • 46,580
  • 12
  • 123
  • 152