Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extjs 4 - Combining two grid columns

Tags:

extjs

extjs4

I have a datastore and a grid. I am trying to declare a new column called FullName that would combine the two dataindexes. After spending some time researching this issue, I understand it could either be a renderer (grid level) or it could be a custom column in the datastore (mapping?).

Can someone provide a code sample that implements such a column?

// XML
<person>
    <first_name>John</first_name>
    <last_name>Smith</last_name>
</person> 

// Store
Ext.create('Ext.data.Store', {
    autoLoad: true,
    storeId: 'TestStore',
    fields: ['first_name', 'last_name'],
    data: parsed_xml_object,
    proxy: {
        type: 'memory',
        reader: {
            type: 'xml',
            record: 'person'
        }
    }
});

// Grid
TestGrid = Ext.create('Ext.grid.Panel', {
    title: 'Test',
    store: Ext.data.StoreManager.lookup('TestStore'),
    columns: [
        { header: 'First Name', dataIndex: 'first_name' },
        { header: 'Last Name Name', dataIndex: 'last_name' },
     ],
    height: 200,
    autowidth: true
});
like image 557
Stan C Avatar asked Aug 08 '11 20:08

Stan C


2 Answers

Use a custom renderer:

{
   header: "Name",
   dataIndex: 'last_name',
   renderer: function(value, element, record) {
       return record.data['last_name'] + ', ' + record.data['first_name'];
   }
}
like image 117
Diodeus - James MacFarlane Avatar answered Oct 19 '22 21:10

Diodeus - James MacFarlane


you can use templeteColumn for it which is a Column definition class which renders a value by processing a Model's data using a configured XTemplate

http://docs.sencha.com/ext-js/4-0/#/api/Ext.grid.column.Template

like image 33
Gopal Saini Avatar answered Oct 19 '22 21:10

Gopal Saini