Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ExtJS: Display model in Ext.grid.property.Grid

Tags:

extjs

I'd like to display the persistent fields (those defined in my model file) in a property grid.

enter image description here

Property Grid:

Ext.define('ATCOM.view.InspectorProperties', {
    extend : 'Ext.grid.property.Grid',
    alias : 'widget.inspectorProperties',
    cls : 'property-grid',
    height : 150,
    listeners : {
        beforerender : function() {
            // Rename the first column
            var cols = this.getView().getHeaderCt().getGridColumns();
            cols[0].setText("Property");
        },
        beforeedit : function(e) {
            // Read-only
            return false;
        }
    },
    source : {} // Start with no items
});

I load items like so in a select event (in a controller), where record is our model object and getInfo() is the property grid:

var source = {};
source.id = record.get('id');
source.start = record.get('start');
source.end = record.get('end');

this.getInfo().setSource(source);

Model:

Ext.define('ATCOM.model.Shift', {
    extend : 'Ext.data.Model',
    fields : [ 'id', {
        name : 'start',
        type : 'date',
    }, {
        name : 'end',
        type : 'date',
    }, 'position', 'controller' ],
    hasMany : {
        model : 'ATCOM.model.ShiftAlloc',
        name : 'allocations'
    }
});

Is there a better way to go about this so all non-associative fields (excluding allocations in my case) are automatically sent to the property grid? It might also be possible to read the fields with ATCOM.model.Shift.getFields() and iterate over those checking for persistent:false; to keep the remaining keys, but how do I get the class reference from an instance - as in, how do I get ATCOM.model.Shift from one of its instances so I can call getFields()?

EDIT:

For finding the class name: http://docs.sencha.com/ext-js/4-1/#!/api/Ext.Base-static-method-getName

like image 805
Aram Kocharyan Avatar asked Nov 12 '22 21:11

Aram Kocharyan


1 Answers

It may work to say setSource(record.data). I am just playing with this now; it seems to show the right information, though you may lose control over the details of which fields to enable for editing, etc.

like image 74
Mark Torrance Avatar answered Dec 24 '22 11:12

Mark Torrance