Results 1 to 2 of 2

Thread: Store with hasMany and grid

  1. #1
    Sencha User
    Join Date
    Jan 2013
    Posts
    8
    Vote Rating
    0
      0  

    Default Store with hasMany and grid

    I have a store with hasMany :

    Code:
    Ext.define('MetExplore.store.S_DataMapping',{
    		extend : 'Ext.data.Store',
    		model: 'MetExplore.model.DataMapping',
            data:{rows:[{'object':'obj1','conditions':[{'condition':'obj1 cond1'},{'condition':'obj1 cond2'}]},
            			{'object':'obj2','conditions':[{'condition':'obj2 cond1'},{'condition':'obj2 cond2'}]}
            	]},
            autoLoad: true
        });
    //models:
    Ext.define('MetExplore.model.DataMapping', {
    		extend : 'Ext.data.Model',
    		fields : [ {name : 'object'}],	//objet du mapping = col1 du fichier de data
            requires : ['MetExplore.model.Condition'],
            
            hasMany : {
    				model : 'MetExplore.model.Condition',
    				name : 'conditions',
    				associationKey : 'conditions'
    			},
       });
    
    Ext.define('MetExplore.model.Condition', {
    			extend : 'Ext.data.Model',
    			fields : [ {
    						name : 'condition',
    						type : 'string'
    					}
    					],
    		});
    i want to have a grid like this :

    obj1 obj1_cond1 obj1_cond2
    obj2 obj2_cond1 obj2_cond2

    for this, i make a view :
    Code:
    Ext.define('MetExplore.view.grid.V_gridData',{
    		extend:'Ext.grid.Panel',
    		alias: 'widget.gridData',
        	store: 'S_DataMapping',
        	
        	// impossible to put it in V_GenericGrid
        	plugins:[Ext.create('Ext.grid.plugin.CellEditing', {
            			clicksToEdit: 2})],
        	
    
    
        	columns:[
            	{
                    text     : 'Identifier OR Name OR Mass',
                    width    : 200,
                    flex     : 1,
                    sortable : true,
                    //filter: {type:'string'},
                    dataIndex: 'object',
                    editor: {
                        allowBlank: false}
            	},
            	{
                    text     : 'Conditions',
                    columns: [                                                             
                    {                                                                  
                        text: 'condition',                               /////////////////////////////////////////////////////////////////////               
                        dataIndex: 'object.conditions[0]',     // i don't know what i put here
                        editor: {allowBlank: false               }/////////////////////////////////////////////////////////////////////
                    },
                    {                                                                  
                        text: 'condition',                                              
                        dataIndex: 'object.conditions[1]',
                        editor: {allowBlank: false}
                    }],                                                               
                    editor: {
                        allowBlank: false
                 	}
            
            }],
    what it this necessary to put in dataIndex information in the view
    Thank you

  2. #2
    Sencha User slemmon's Avatar
    Join Date
    Mar 2009
    Location
    Boise, ID
    Posts
    6,165
    Answers
    505
    Vote Rating
    255
      0  

    Default

    You won't be able to link directly to the associated records' data using the mapping config. You can load nested data to the grid (without associations) and map through the nested data structure or you might be able to use a renderer and then return record.getMyAssocStore().get('requiredFieldForThatColumn').

    The first option would be the one I'd pursue personally and just have my server structure the data nested for me on the first load - I think that will ultimately be the most performant option for you, but the associated data pull in the column renderer may be viable for you as well.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •