Z
Z
z00912014-04-03 17:31:36
ExtJS/Sencha
z0091, 2014-04-03 17:31:36

Ext.JS 4+ How to display related data in Ext.grid.Panel?

Hey! Faced the following problem.
There are 2 data models:

Ext.define('ParserGoods.model.GroupList', {
    extend: 'Ext.data.Model',
    fields: [
        'group_id', 'infoblock_id', 'id', 'group_name',
    ],

    associations: [
        {type: 'belongsTo', model: 'ParserGoods.model.InfobloksList',    name: 'infoblock'}
    ],

    proxy: {
        type: 'ajax',
        url: '/group/getlist',
        reader: {
            root: 'data',
            totalProperty: 'totalCount',
            type: 'json'
        },
        simpleSortMode: true
    }

});

Ext.define('ParserGoods.store.GroupListStore', {
    extend: 'Ext.data.Store',
    model: 'ParserGoods.model.GroupList',

    storeId: 'GroupListStore',

    remoteSort: true,
    pageSize: 20,

    sorters: [{
        property: 'group_name',
        direction: 'DESC'
    }],

    autoLoad: true
});

As you can see, the GroupList model is related to the InfobloksList model as "many to one".
The following response comes from the server
{
    "infoblock": {
        "infoblock_name":"Комплектующие",
        "infoblock_id":"1",
        "insert_time":"2014-04-03 13:25:49",
        "id":"27"
    },
    "group_name":"Сетевые адаптеры",
    "group_id":"60c83bfa",
    "infoblock_id":"1",
    "id":"153"
},{
    "infoblock": {
        "infoblock_name":"Комплектующие",
        "infoblock_id":"1",
        "insert_time":"2014-04-03 13:25:49",
        "id":"27"
    },
    "group_name":"Сетевые адаптеры",
    "group_id":"60c83bfa",
    "infoblock_id":"1",
    "id":"153"
}

I can't figure out how to insert this data into Ext.grid.Panel. With all this, I need sorting and searching in all fields.
Tried like this:
{
    text     : 'Id группы',
    flex: 1,
    dataIndex: 'group_id',
    filter: {
        type: 'string'
    }
},{
    text     : 'Название группы',
    flex: 1,
    dataIndex: 'group_name',
    filter: {
        type: 'string'
    }
},{
    text     : 'infoblock_name',
    flex: 1,
    dataIndex: 'infoblock.infoblock_name',
    filter: {
        type: 'string'
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
lfs, 2015-01-28
@lfs

try

Ext.define('ParserGoods.model.GroupList', {
    extend: 'Ext.data.Model',
    fields: [
  {
        name: 'group_id',
        mapping: 'infoblock.group_id'
    },
  {
        name: 'group_id',
        mapping: 'infoblock.group_id'
    },
  {
        name: 'group_name',
        mapping: 'infoblock.group_name'
    }
    ],

    associations: [
        {type: 'belongsTo', model: 'ParserGoods.model.InfobloksList',    name: 'infoblock'}
    ],

    proxy: {
        type: 'ajax',
        url: '/group/getlist',
        reader: {
            root: 'data',
            totalProperty: 'totalCount',
            type: 'json'
        },
        simpleSortMode: true
    }

});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question