Code:
Ext.onReady(function() {
var arrayStore = {
xtype: 'array',
fields: ['id', 'name'],
data: {
'items': [{
id: '1',
name: 'a'
}, {
id: '2',
name: 'b'
}, {
id: '3',
name: 'c'
}, {
id: '4',
name: 'd'
}, {
id: '5',
name: 'e'
}, {
id: '6',
name: 'f'
}]
},
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'items'
}
}
};
var columns = [{
header: 'Id',
dataIndex: 'id'
}, {
header: 'Name',
dataIndex: 'name'
}];
var toolBar = {
items: [{
xtype: 'button',
text: 'btn1',
hidden: true
}, {
xtype: 'button',
text: 'btn2',
hidden: true
}, {
xtype: 'button',
text: 'btn3',
hidden: true
}, {
xtype: 'button',
text: 'btn4',
hidden: true
}, {
xtype: 'button',
text: 'btn5',
hidden: true
}, {
xtype: 'button',
text: 'btn6',
hidden: true
}]
};
Ext.create('Ext.container.Viewport', {
layout: 'fit',
items: {
xtype: 'grid',
store: arrayStore,
columns: columns,
tbar: toolBar,
multiSelect: true,
scope: this,
listeners: {
'selectionchange': function(sm, selected) {
var toolbar = this.down('toolbar'),
items = toolbar.items,
len = items.getCount(),
i = 0,
visible = selected.length > 0,
d = new Date();
Ext.suspendLayouts();
for (; i < len; ++i) {
items.getAt(i).setVisible(visible);
}
Ext.resumeLayouts(true);
console.log(new Date() - d);
}
}
}
});
});