Ext.onReady(function() {var csm = new Ext.grid.CheckboxSelectionModel({//创建checkbox对象
handleMouseDown: newExt.emptyFn()
});var cum = newExt.grid.ColumnModel([
csm,//checkbox对象
{header: "用户ID", dataIndex: "id", sortable: true},
{ header:'用户姓名', dataIndex: 'name', sortable: true,
editor:newExt.grid.GridEditor(new Ext.form.TextField({ allowBlank: false}))
},
{ header:'性别', dataIndex: 'sex', sortable: true,
editor:newExt.grid.GridEditor(new Ext.form.TextField({ allowBlank: false}))
}
]);
;var store = newExt.data.Store({
proxy:new Ext.data.HttpProxy({ url: 'UserData.aspx'}),
reader:newExt.data.JsonReader({
totalProperty:'totalCount', //json字符串中的字段,数据量大小
root: 'data'//json字符串中的字段
}, [
{ name:'id'},
{ name:'name'},
{ name:'sex'}
]),
remoteSort:true});var Record =Ext.data.Record.create([
{ name:'id', type: 'string'},
{ name:'name', type: 'string'},
{ name:'sex', type: 'string'}
]);
store.load({ params: { start:0, limit: 5} }); //运行加载表格数据
var cumgrid = newExt.grid.EditorGridPanel({
renderTo:'cumGrid',
store: store,
stripeRows:true, //斑马线效果
viewConfig: {
forceFit:true,
columnsText:"显示的列",
sortAscText:"升序",
sortDescText:"降序"},
height:200,
width:550,
sm: csm,
bbar:newExt.PagingToolbar({
pageSize:5, //每页信息条数
store: store,
autowidth:true,
autoHeight:true,
displayInfo:true,
prevText:"上一页",
nextText:"下一页",
refreshText:"刷新",
lastText:"最后页",
firstText:"第一页",
beforePageText:"当前页",
afterPageText:"共{0}页",
displayMsg:'显示第{0}条到第{1}条记录,一共{2}条',
emptyMsg:'没有记录'}),
tbar:new Ext.Toolbar(['-', {
text:'添加一行',
handler:function() {var win = newExt.Window({
title:'添加用户',
layout:'fit',
height:300,
width:300,
border:0,
frame:true, //去除窗体的panel框架
plain: true,
html:''});
win.show();//显示窗口
}
},'-', {
text:'删除一行',
handler:function() {
Ext.Msg.confirm('信息', '确定要删除?', function(btn) {if (btn = 'yes') {var id = "";functiongetid() {for (var i = 0; i < cumgrid.getSelectionModel().getSelections().length; i++) {
id+= cumgrid.getSelectionModel().getSelections()[i].get("id");
id+= ',';
}
};
getid();//初始化选中行id字符串数组
Ext.Ajax.request({
url:"DelUserInfo.aspx",
method:"post",
params: { id: id },
success:function(response) {
Ext.Msg.alert("恭喜", "删除成功了!");
store.reload();
},
failure:function() {
Ext.Msg.alert("提 示", "删除失败了!");
}
})
}
});
}
},'-', {
text:'保存',
handler:function() {var m = store.getModifiedRecords().slice(0);var jsonArray =[];
Ext.each(m,function(item) {
jsonArray.push(item.data);
})if (false) {//判断条件
return;
}else{//alert(Ext.encode(jsonArray))
Ext.Ajax.request({//url: "Demo/Operator.aspx",
url: "SaveUserInfo.aspx",
method:"POST",
params:'data=' +encodeURIComponent(Ext.encode(jsonArray)),
success:function(response, option) {
store.reload();
alert(response.responseText);
},
failure:function(response) {
store.reload();
alert(response.responseText)
Ext.Msg.alert("提示", "修改失败了!");
}
});
}
}
},'-']),
cm: cum
});
cumgrid.render();//刷新表格
});