© 1999-2048 dssz.net 粤ICP备11031372号
"; }else{ return "女
"; } } var cm = new Ext.grid.ColumnModel([ {header:'编号',dataIndex:'id',editor:new Ext.grid.GridEditor(new Ext.form.TextField({ allowBlank:false }))}, {header:'性别',dataIndex:'sex',editor:new Ext.grid.GridEditor(new Ext.form.TextField({ allowBlank:false }))}, {header:'名称',dataIndex:'name',editor:new Ext.grid.GridEditor(new Ext.form.TextField({ allowBlank:false }))}, {header:'描述',dataIndex:'descn',editor:new Ext.grid.GridEditor(new Ext.form.TextField({ allowBlank:false }))} ]); var ds = new Ext.data.Store({ proxy: new Ext.data.PagingMemoryProxy(data), reader: new Ext.data.ArrayReader({}, [ {name: 'id',mapping: 0}, {name: 'sex',mapping: 1}, {name: 'name',mapping: 2}, {name: 'descn',mapping: 3} ]), sortInfo:{field:"name",direction:"ASC"} }); var grid = new Ext.grid.EditorGridPanel({ el: 'grid', ds: ds, cm: cm, bbar:new Ext.PagingToolbar({ pageSize:3, store:ds, displayInfo:true, displayMsg:"显示第{0}条到{1}条记录,一共{2}条", emptyMsg:"没有记录", beforePageText:"第", afterPageText:'页 共{0}页', firstText:'首页', prevText:'上一页', nextText:'下一页', lastText:'尾页', refreshText:'刷新' }), tbar: new Ext.Toolbar([ '-', {text:'添加一行',handler: function(){ var initValue = {id:'', name:'', descn:''}; var p = new Record(initValue); grid.stopEditing(); ds.insert(0, p); grid.startEditing(0, 0); p.dirty = true; p.modified = initValue; if(ds.modified.indexOf(p) == -1){ ds.modified.push(p); } } }, '-', {text:'删除一行',handler:function(){ Ext.Msg.confirm('信息','确定删除?',function(btn){ if(btn == 'yes'){ var sm = grid.getSelectionModel(); var cell = sm.getSelectedCell(); var record = ds.getAt(cell[0]); ds.remove(record); } }); } }, '-', {text:'保存',handler:function(){ var m=ds.modified.slice(0); var jsonArray = []; Ext.each(m, function(item){ jsonArray.push(item.data); }); Ext.lib.Ajax.request( 'POST', 'save.php', {success: function(response){ Ext.Msg.alert('信息',response.responseText, function(){ ds.reload(); }); },failure: function(){ Ext.Msg.alert("错误","与后台联系的时候出现了错误"); }}, 'data=' + encodeURIComponent(Ext.encode(jsonArray)) ); } } ]) }); var Record = Ext.data.Record.create([ {name:'id', type:'string'}, {name:'name', type:'string'}, {name:'descn', type:'string'} ]); ds.load({params:{start:0,limit:3}}); grid.render(); ...展开收缩