//增删改
var store;
var ExtappContentItemJKGrid;
Ext.onReady(function () {
Ext.define('Ext.app.ContentItemData',
{
extend: 'Ext.data.Model',
fields:
[
//第一个字段需要指定mapping,其他字段,可以省略掉。
{
name: 'UserID',
mapping: 'UserID',
type: 'string'
},
{
name: 'UserName',
type: 'string'
}, {
name: 'Sex',
type: 'string'
},
{
name: 'Age',
type: 'string'
},
{
name: 'XueHao',
type: 'string'
},
{
name: 'BanJi',
type: 'string'
}
]
});
store = Ext.create('Ext.data.Store',
{
model: 'Ext.app.ContentItemData',
pageSize: 20,
proxy:
{
type: 'ajax',
url: 'GetTestData',
reader:
{
type: 'json',
root: 'items',
totalProperty: 'total'
}
},
listeners: {
load: function () {
var addClick = Ext.getCmp("ctiJKAdd");
var EditClick = Ext.getCmp("ctiJKEdit");
var deleteClick = Ext.getCmp("ctiJKdelete");
// alert(addClick);
if (addClick) {
if (ExtappContentItemJKGrid.ctiId == 0) addClick.disabled = true;
else addClick.disabled = false;
}
if (EditClick) {
if (ExtappContentItemJKGrid.ctiId == 0) EditClick.disabled = true;
else EditClick.disabled = false;
}
if (deleteClick) {
if (ExtappContentItemJKGrid.ctiId == 0) deleteClick.disabled = true;
else deleteClick.disabled = false;
}
if (ExtappContentItemJKGrid.store.data.length > 0) {
ExtappContentItemJKGrid.getSelectionModel().select(0); // checkbom默认选择一个
}
ctijkClick();
}
},
autoLoad: true
});
ExtappContentItemJKGrid = Ext.create('Ext.grid.Panel',
{
title: '学生列表',
region: 'north',
id: 'am-contentitemjkgrid',
height: 150,
ctiId: 0,
ctiName: '',
wsId: 0,
selType: 'rowmodel', //rowmodel cellmodel
renderTo: Ext.getBody(),
viewConfig:
{
id: 'ctigv',
trackOver: true,
stripeRows: true
},
columns: [
{ text: "ID", width: 120, dataIndex: 'UserID', sortable: true },
{ text: "姓名", width: 120, dataIndex: 'UserName', sortable: true },
{ text: "性别", flex: 1, dataIndex: 'Sex', sortable: false },
{ text: "年龄", width: 100, dataIndex: 'Age', sortable: true },
{ text: "学号", width: 100, dataIndex: 'XueHao', sortable: true },
{ text: "班级", width: 100, dataIndex: 'BanJi', sortable: true}],
store: store,
dockedItems:
[{
dock: 'top',
xtype: 'toolbar',
items:
[
{
width: 80,
xtype: 'button',
id: "ctiJKAdd",
text: '添加',
// store: store,
// handler: ctijkAdd
listeners: { click: { element: 'el', //bind to the underlying el property on the panel
fn: ctijkAdd } }
},
{
width: 50,
xtype: 'button',
id: "ctiJKEdit",
text: '编辑',
//store: store,
//handler: ctijkEdit
listeners: { click: { element: 'el', //bind to the underlying el property on the panel
fn:ctijkEdit } }
},
{
width: 50,
xtype: 'button',
id: "ctiJKdelete",
text: '删除' ,
//store: store,
// handler:
listeners: { click: { element: 'el', //element: 'body', //bind to the underlying body property on the panel
fn: ctijkDelete
}
}
}
]
}]
});
});
/定义删除事件
function ctijkDelete() {
alert('ctijkDelete');
var el = ExtappContentItemJKGrid.getEl();
var records = ExtappContentItemJKGrid.getSelectionModel().getSelection();
var array;
//records.length 记录条数
// records[0].fields.items.length 字段个数
// records[i].fields.items[j].name // "UserID" 取第j个字段名
// records[0].data //实例
// Age: "22"
// BanJi: "中文系"
// Sex: "男"
// UserID: "2"
// UserName: "李四"
// XueHao: "002"
// records[0].data.Age // "22"//取实例中属性值
// records[0].get('UserID'); //根据字段取值
//将选择的记录放入数组中 只能选择一条记录
if (records.length > 0) {
array = new Array(records[0].fields.items.length);
for (var i = 0; i < records.length; i++) {
for (var j = 0; j < records[0].fields.items.length; j++) {
array[j] = records[i].get(records[i].fields.items[j].name);
}
}
} var row = ExtappContentItemJKGrid.getSelectionModel().getSelection();
if (row.length == 0) {
Ext.Msg.alert("提示", "请选择一行");
}
else {
Ext.Msg.confirm("提示", "确定删除这" + row.length + "条信息吗?",
function (btn) {el.mask("正在删除中……");
if (btn == "yes") {
Ext.Ajax.request({
url: "TestDoorder",
method: "POST",
params: { id: array}, //发送的参数
success: function (response, option) {
response = Ext.JSON.decode(response.responseText);
if (response.success == true) {
if (response.flag == true) {el.unmask();
Ext.MessageBox.alert("提示", "删除成功!");
//刷新列表
ExtappContentItemJKGrid.store.load();
}
else { el.unmask(); Ext.MessageBox.alert("错误信息", "删除失败!"); }
}
else { el.unmask(); Ext.MessageBox.alert("错误信息", response.msg); }
},
failure: function () {el.unmask(); Ext.Msg.alert("提示", "删除失败<br>没有捕获到异常"); }
});
}
})
}
}
/复选框选择事件
function ctijkClick() {
alert('ctijkClick');
根据选中的行显示相应内容栏数据
var ctcgridview = Ext.getCmp('am-contentcolumngrid');
if (ExtappContentItemJKGrid.store.data.length > 0) {
ctcgridview.wsName = ExtappContentItemJKGrid.getSelectionModel().getSelection()[0].get("WsName"); //可以给另一个grid属性赋值
ctcgridview.wsId = ExtappContentItemJKGrid.getSelectionModel().getSelection()[0].get("WsId");
ctcgridview.ctiName = ExtappContentItemJKGrid.getSelectionModel().getSelection()[0].get("CtItemName");
} else { ctcgridview.wsId = 0 }
// alert(ctcgridview.wsId);
ctcgridview.ctiId = ExtappContentItemJKGrid.ctiId;
ctcgridview.store.load({
url: 'TestDoorder',
params: { msg: ExtappContentItemJKGrid.ctiId }
});
}
定义添加事件
function ctijkAdd() {
alert('ctijkAdd');
var ctiWin = Ext.create('Ext.app.ContentItemJKAddForm', {
ctiId: ExtappContentItemJKGrid.ctiId,
ctiName: ExtappContentItemJKGrid.ctiName
});
ctiWin.show();
}
定义编辑事件
function ctijkEdit() {
alert('ctijkEdit');
var row = ExtappContentItemJKGrid.getSelectionModel().getSelection();
if (row.length == 0) {
Ext.Msg.alert("提示", "请选择一行");
} else if (row.length > 1) {
Ext.Msg.alert("提示", "只能选择一行");
} else if (row.length == 1) {
var ctiInId = row[0].get('Id');
if (ctiInId != 0) {
var editwin = Ext.create('Ext.app.ContentItemJKEditForm', { Id: ctiInId });
editwin.show();
Ext.getCmp("am-contentitemjkeditform").getForm().load(
{
url: "TestDoorder",
params: { Id: ctiInId },
waitTitle: "请等待",
waitMsg: "正在加载数据...",
success: function (form, action) {
},
failure: function (form, action) {
Ext.Msg.alert("提示", "数据加载失败!");
}
});
}
}
}
[HttpPost]
public JsonResult TestDoorder(string para1,string para2,string para3 )
{
//后台数据库操作XXX
resultRtn re = new resultRtn() {
success = true
,flag=true
,msg="没有错误信息"
};
return Json(re);
//或 return Json(new { success = false, msg = "错误信息错误信息错误信息错误信息错误信息错误信息" });
}
/// <summary>
/// 返回结果类
/// </summary>
public class resultRtn
{
public bool success { get; set; }
public bool flag { get; set; }
public string msg { get; set; }
}