创建表格 要用grid.Panel
grid.Panel | columns | tbar | dockedItems |
---|
第一列文本居中 | 第二列文本居右 | Ext.window.Window | 控制组件位置,buttom |
var grid = Ext.create("Ext.grid.Panel", {
title : '列表页1111',
frame : true,
width : 700,
height : 550,
columns : [
{
text : "主键",
dataIndex : 'id',
width : 100
},
{
text : "姓名",
dataIndex : 'name',
width : 100
},
{
text : "性别",
dataIndex : 'sex',
width : 100
},
{
text : "生日",
dataIndex : 'birth',
width : 350,
field : {
xtype : 'textfield',
allowBlank : false
}
}
],
tbar : [
{
xtype : 'button',
text : '添加',
iconCls : 'fa fa-plus',
handler : function(o) {
AddDialog.setTitle("添加数据");
AddForm.form.reset();
AddDialog.show();
}
}, {
xtype : 'button',
text : '删除',
iconCls : 'table_remove',
handler : function(o) {
var gird = o.ownerCt.ownerCt;
var data = gird.getSelectionModel().getSelection();
if (data.length == 0) {
Ext.Msg.alert("提示", "您最少要选择一条数据");
} else {
var st = gird.getStore();
var ids = [];
Ext.Array.each(data, function(record) {
ids.push(record.get('id'));
})
Ext.Ajax.request({
url : _ctx + '/user/batchDelete.action',
params : {
ids : ids.join(",")
},
method : 'POST',
timeout : 2000,
success : function(response, opts) {
var respText = response.responseText;
if (respText.indexOf('成功') != -1) {
Ext.Array.each(data, function(
record) {
st.remove(record);
})
}
Ext.Msg.alert("提示", respText);
}
})
}
}
}, {
xtype : 'button',
text : '修改',
iconCls : 'table_edit',
handler : function(o) {
var gird = o.ownerCt.ownerCt;
var data = gird.getSelectionModel().getSelection();
if (data.length != 1) {
Ext.Msg.alert("提示", "您必须要选择一条数据");
} else {
var record = data[0];
AddDialog.setTitle("添加数据");
AddForm.form.reset();
Ext.getCmp("btnAdd").show();
Ext.getCmp("text_id").setValue(record.get('id'));
Ext.getCmp("text_name").setValue(record.get('name'));
Ext.getCmp("text_sex").setValue(record.get('sex'));
Ext.getCmp("text_birth").setValue(record.get('birth'));
AddDialog.show();
}
}
}, {
xtype : 'textfield',
id : 'KeyWord'
}, {
text : '搜索',
handler : function(o) {
var gird = o.ownerCt.ownerCt;
var st = gird.getStore();
var searchParam=Ext.getCmp("KeyWord").getValue();
st.load({
params:{
name : searchParam
}
});
}
}
],
dockedItems : [{
xtype : 'pagingtoolbar',
store : Ext.data.StoreManager.lookup('s_user'),
dock : 'bottom',
displayInfo : true
}],
plugins : [
Ext.create("Ext.grid.plugin.CellEditing", {
clicksToEdit : 1
})],
selType : 'checkboxmodel',
multiSelect : true,
renderTo : 'gridDiv',
store : Ext.data.StoreManager.lookup('s_user')
});