87,991
社区成员
发帖
与我相关
我的任务
分享 var sel = '<select><option value="克重">克重</option><option value="指圈号">指圈号</option></select>', maxNum = 2;//这变量要依据你下拉框的option来设置
function addRow() {
var grid = Ext.getCmp('myGrid');
var store = grid.getStore();
store.add({ id: store.getCount() + 1, listname: '', name: '' });
if (store.getCount() >= maxNum) Ext.get('imgADD').hide();
}
Ext.onReady(function () {
var store = Ext.create('Ext.data.Store', {
fields: ['id', 'listname', 'name'],
data: { 'items': [{ id: 1, listname: '规格', name: '克重' }, { id: 2, listname: 'Size', name: '指圈号'}] },
proxy: { type: 'memory', reader: { type: 'json', root: 'items'} }
});
var grid = Ext.create('Ext.grid.Panel', {
store: store,
width: 400,
id: 'myGrid',
columns: [
{ text: '序号', dataIndex: 'id', width: 50 },
{ text: '前台显示名称', dataIndex: 'listname', flex: 1, renderer: function (v) { return '<input type="text" value="' + v + '"/>'; } },
{ text: '规格名称', dataIndex: 'name', width: 150, renderer: function (v) { return sel.replace(v + '"', v + '" selected'); } },
{
xtype: 'actioncolumn',
text: '操作',
width: 60,
altText: '删除',
sortable: false,
items: [{
icon: 'del.gif',
tooltip: '删除',
handler: function (grid, rowIndex, colIndex) {
if (confirm('确认删除?!!')) {
store.removeAt(rowIndex);
Ext.get('imgADD').show();
}
}
}]
}]
});
Ext.create('Ext.Panel',
{
bodyPadding: '30 25 5 25',
width: 600,
listeners: { render: function () { if (store.getCount() >= maxNum) Ext.get('imgADD').hide(); } },
renderTo: document.body,
items: [
{ xtype: 'panel', layout: { type: 'table', columns: 2, itemCls: 'xxxxxxxxxxx', tdAttrs: { valign: 'bottom'} }, border: false, height: 200, items: [grid, { border: false, html: ' <img src="add.gif" alt="+" id="imgADD" onclick="addRow()"/>'}] },
{ xtype: 'panel', height: 30, items: [
{ width: 100, height: 25, xtype: 'button', text: '保存', handler: function () {
var s = '';
store.each(function (r) {
s += Ext.encode(r.raw)
});
alert(s)
}
},
{ width: 100, height: 25, xtype: 'button', margin: '0 0 0 30', text: '重置', handler: function () {
if (confirm('确认重置?将会删除所有数据?!')) store.removeAll();
}
}], border: false
},
{ xtype: 'panel', height: 40, border: false, html: '<div style="color:red">备注:1.目前暂定规格....<br/> 2.同一个规格...,列表的<img src="add.gif" alt="+"/>按钮不再显示</div>' }
]
});
});
加班中