Mutant
Mutant

Reputation: 3821

Extjs with Radiogroup

can we bind static json store with radiogroup in ext?

Upvotes: 4

Views: 6070

Answers (2)

user3710246
user3710246

Reputation: 1

You can use dataView for this operation. Depending on store value you can add radio buttons. Suppose your store has 5 items than 5 radio buttons will be displayed.

    var tpl = new Ext.XTemplate('<tpl for=".">', '<div class="thumb-wrap" style="width:210px; float: left;">', '<label >', '<tpl>', '<input type=radioField value={fieldId} >', '</tpl>', '{dataViewFieldName}', '</label>', '</div>', '</tpl>', {            
    });
    var me = this;

this.items = new Ext.DataView({
        store: this.store,
        tpl: tpl,            
        overClass: 'x-view-over',
        itemSelector: 'div.thumb-wrap',           
        autoScroll: true            
    });
    this.callParent();
},  

Upvotes: 0

Christopher WJ Rueber
Christopher WJ Rueber

Reputation: 2161

Radiogroups and Stores are not directly related in ExtJS. It's easy to populate form values from a store, but using a store to actually create the fields requires a slight work around. Specifically, you would have to do something like this (assuming Ext 3.3.1), and that your JsonStore is already set up...

var store = <your predefined store, with records>;
var itemsInGroup = [];

store.each( function(record) {
  itemsInGroup.push( {
      boxLabel: record.someLabel, 
      name: record.someName, 
      inputValue: record.someValue
    });  
});

var myGroup = { 
  xtype: 'radiogroup', 
  fieldLabel: 'My Dynamic Radiogroup', 
  items: itemsInGroup 
};

Upvotes: 8

Related Questions