0
我已激活每個網格行上的按鈕,因此用戶只能激活他們想要編輯的行,並且按鈕更改爲deactivate.how,我可以保存按鈕的狀態以便下次打開時重新打開面板?下面是我的代碼,也:https://fiddle.sencha.com/#fiddle/ofpExtjs Cellediting按鈕
Ext.application({
name : 'Fiddle',
launch : function() {
Ext.create('Ext.data.Store', {
storeId:'simpsonsStore',
fields:['name', 'email', 'phone'],
data:{'items':[
{"id": 1, "name":"Lisa", "email":"[email protected]", "phone":"555-111-1224"},
{"id": 2, "name":"Bart", "email":"[email protected]", "phone":"555--222-1234"},
{"id": 3, "name":"Homer", "email":"[email protected]", "phone":"555-222-1244"},
{"id": 4, "name":"Marge", "email":"[email protected]", "phone":"555-222-1254"}
]},
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'items'
}
}
});
Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
store: Ext.data.StoreManager.lookup('simpsonsStore'),
columns: [
{header: 'Name', dataIndex: 'name', editor: 'textfield'},
{header: 'Email', dataIndex: 'email', flex:1, editor: 'textfield'},
{header: 'change status', renderer: extjsRenderer},
{header: 'Phone', dataIndex: 'phone', editor: 'textfield'}
],
height: 200,
width: 600,
renderTo: Ext.getBody(),
selType: 'rowmodel',
plugins: [
Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 1,
listeners: {
beforeEdit: function(editor, e) {
var button = Ext.getCmp('editButton_' + e.record.get('id'));
if (button.active)
return true;
else
return false;
}
}
})
]
});
代碼激活/關閉按鈕:
function extjsRenderer(val,meta,rec) {
var id = Ext.id();
Ext.defer(function() {
Ext.widget('button', {
renderTo: id,
id:'editButton_' + rec.get('id'),
text: 'Activate',
width: 75,
handler: function() {
if (this.active == null || this.active == false) {
this.active = true
this.setText('Deactivate');
return;
}
if (this.active == true) {
this.active = false;
this.setText('Activate');
return;
}
}
});
// }
}, 50);
return Ext.String.format('<div id="{0}"></div>', id);
}
}
});
非常感謝您的幫助。我實際上修改了你的代碼,因爲我需要每行中的按鈕也將rowediting更改爲cellediting,但它不能正常工作,請你檢查它並幫助嗎? https://fiddle.sencha.com/#fiddle/ofp – user2812642
看看我上面的鏈接提琴。每個按鈕都需要一個唯一的ID。我向json添加了一個id屬性來標識哪一行將被啓用進行編輯。 – Tyr
非常感謝,它的工作!我只需要保存狀態。目前,當我重新打開面板時,所有按鈕都重置爲「激活」。所以,如果它被激活之前我如何保存下一次? – user2812642