ExtJs 4.1: Read complex json with hasOne association

Posted By Vitaliy | September 15, 2012 | ExtJS 4.1.0
0 4828
Ext.data.association.HasOne - represents a one to one association with another model.
The owner model is expected to have a foreign key which references the primary key of the associated model

Js Code

Ext.define('User', {
    extend: 'Ext.data.Model',
    fields: ['id', 'name'],
    associations: [{ type: 'hasOne', model: 'Status', associationKey: 'status'}]
});

Ext.define('Status', {
    extend: 'Ext.data.Model',
    fields: [
        { name: 'id', type: 'int' },
        { name: 'title', type: 'string', mapping: 'st_title' }
    ]
});
            

ExtJs 4.1 TreeGrid Treecolumn Custom Icon

Posted By Vitaliy | September 05, 2012 | ExtJS 4.1.0
0 4832
To set treecolumn icon you can use "iconCls" property.

Js Code

Ext.define('MenuItem', {
    extend: 'Ext.data.Model',
    idProperty: 'Id',
    fields: [
        { name: 'Id', type: 'string' },
        { name: 'Name', type: 'string' },
        { name: 'Disabled', type: 'bool' },
        {
            name: 'iconCls',
            type: 'string',
            convert: function (v, r) {
                return r.get('Disabled') ? 'icon-disabled' : 'icon-enabled'
            }
        }
    ]
});
            

ExtJs 4: How To Add Grid Cell Tooltip

Posted By Vitaliy | August 31, 2012 | ExtJS 4.1.0
0 8417
We can use grid column renderer.

Js Code

// Init the singleton.  Any tag-based quick tips will start working.
Ext.tip.QuickTipManager.init();

...

{
    header: 'comment',
    dataIndex: 'comment',
    flex: 1,
    renderer: function (value, meta, record) {
        var max = 15;
        meta.tdAttr = 'data-qtip="' + value + '"';
        return value.length < max ? value : value.substring(0, max - 3) + '...';
    }
}