extjs做的添加,刪除給大家分享一下.加載數據的數據


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>分支機構管理</title>
<link rel="stylesheet" type="text/css"
href="../resources/css/ext-all.css" />
<script type="text/javascript" src="../resources/js/ext-base.js"></script>
<script type="text/javascript" src="../resources/js/ext-all.js"></script>
<script type="text/javascript" src="../resources/js/ext-lang-zh_CN.js"></script>


<script type="text/javascript" src="../js/company/company.js" defer="defer"></script>

</head>
<body>
<!-- <div id="grid"></div>-->


</body>
</html>

----------------------------------html

Ext.onReady(function() {

var add = new Ext.Window({
title : "添加貨物",

hideLabels : false,

width : 280,
height : 410,
closeAction:"hide",
buttonAlign : "left",
items : [

{
items : [{
xtype : "form",
defaultType : "textfield",
id : "form",
labelWidth : 100,

frame : true,
items : [{


fieldLabel : "分支機構名稱",
name : "name",
value : "",

allowBlank : false,
blankText : "名稱不能爲空"
},{


fieldLabel : "固定電話區號碼",
name : "",
value : ""
},
{


fieldLabel : "分支機構ID",
name : "companyid",
value : ""
},new Ext.form.ComboBox({
store:new Ext.data.SimpleStore({
fields:['typeID','typeName'],
data:[['0','0'],['1','生產企業'],['2','銷售企業'],['3','其他']]
}),
displayField:'typeName',
valueField:'typeID',
mode:'local',
typeAhead:true,
triggerAction:'all',
fieldLabel:'企業類型',
name:'companytype',
allowBlank:false,
editable:false,
width:140,
id:'companytype'
}),{

xtype : "numberfield",
fieldLabel : "負責人",
name : "principal",
value : "",
allowBlank : false,
blankText : "長不能爲空"

}, {

xtype : "numberfield",
fieldLabel : "職務",
name : "duty",
value : "",
allowBlank : false,
blankText : "寬不能爲空"
}, {

xtype : "numberfield",
fieldLabel : "電話",
name : "phone",
value : "",
allowBlank : false,
blankText : "高不能爲空"
}, {

xtype : "numberfield",
fieldLabel : "手機",
name : "mobile",
value : "",
allowBlank : false,
blankText : "高不能爲空"
}, {

xtype : "numberfield",
fieldLabel : "傳真",
name : "fax",
value : "",
allowBlank : false,
blankText : "高不能爲空"
}, {

xtype : "numberfield",
fieldLabel : "詳細地址",
name : "address",
value : "",
allowBlank : false,
blankText : "高不能爲空"
}, {

xtype : "numberfield",
fieldLabel : "郵編",
name : "postalCode",
value : "",
allowBlank : false,
blankText : "高不能爲空"
}, {

xtype : "numberfield",
fieldLabel : "email",
name : "email",
value : "",
allowBlank : false,
blankText : "您輸入的電子郵件有誤"
}]
}],

buttons : [{
text : "添加",
handler : function() {
Ext.getCmp("form").form.submit({
waitMsg : "正在處理中...",
url : "../company/insertCompany.shtml",
method : "POST",
success : function(action, form) {
Ext.Msg.alert("操作成功");

store.reload();

//window.location.href = "/wutai/company/queryCompanyPagedList.shtml?firstQuery=true&type=0";

add.close();
}
// failure:function(action,form){
// / alert("矢敗");
// }

});

}

}, {
text : "重置",
handler : function() {
Ext.getCmp("form").form.reset();
}
}]
}]
});


function handleDelete(){
var selectedKeys = grid.selModel.selections.keys; //returns array of selected rows ids only
if(selectedKeys.length > 0)
{
Ext.MessageBox.confirm('提示','您確實要刪除選定的記錄嗎?', deleteRecord);
}
else
{
Ext.MessageBox.alert('提示','請至少選擇一條記錄!');
}//end
}

function deleteRecord(btn){
if(btn=='yes'){
var selectedRows = grid.selModel.selections.items;//returns record objects for selected rows (all info for row)
var selectedKeys = grid.selModel.selections.keys;
//var deleteresult = AjaxRequest('/EmployeeService.svc/DelEmployee',selectedKeys,false,"")
Ext.MessageBox.show({
msg: '正在請求數據, 請稍侯',
progressText: '正在請求數據',
width:300,
wait:true,
waitConfig: {interval:200}
});
Ext.Ajax.request({
url: '../company/deleteCompany.shtml', //url to server side script
method: 'POST',
params:Ext.util.JSON.encode(selectedKeys),//the unique id(s)
params:{companyid:grid.getSelectionModel().getSelected().get('companyid')},
//the function to be called upon failure of the request (server script, 404, or 403 errors)
failure:function(response,options){
Ext.MessageBox.hide();
ReturnValue = Ext.MessageBox.alert("警告","出現異常錯誤!請聯繫管理員!");
},
success:function(response,options){
Ext.MessageBox.hide();
store.reload();
}
})// end Ajax request
}//end if click 'yes' on button
} // end deleteRecord


// var data=[["1","2","3","4"]];
// var store=new Ext.data.SimpleStore({
// data:data, fields:["sales","state","unit","datatime"]
// });
var sm = new Ext.grid.CheckboxSelectionModel();

var cm = new Ext.grid.ColumnModel([sm,

{header : "公司編號",

dataIndex : "companyid"
}, {
header : "名稱",

dataIndex : "name"

}, {
header : "負責人",

dataIndex : "principal"
},{
header : "職務",

dataIndex : "duty"
},{
header : "電話",

dataIndex : "phone"
},{
header : "手機",

dataIndex : "mobile"
},{
header : "傳真",

dataIndex : "fax"
},{
header : "地址",

dataIndex : "address"
},{
header : "郵政編碼",

dataIndex : "postalCode"
},{
header : "添加時間",

dataIndex : "createtime"
}

]);

var store=new Ext.data.Store({proxy:new Ext.data.HttpProxy({url:"../company/queryCompanyPagedList.shtml?firstQuery=true&auditingflag=1"}),


reader: new Ext.data.JsonReader({totalProperty: 'totalNum',root: 'root'},["companyid", "name", "principal", "duty", "phone", "mobile", "fax", "address", "posttalcode", "craetetime"])
});
var grid = new Ext.grid.GridPanel({
renderTo : Ext.getBody(),
id : "business",
title : "分支機構管理",
cm : cm,
sm : sm,
height : 570,
store : store,
viewConfig : {
forceFit : true
},
tbar : [{
text : "添加",
listeners : {
"click" : function() {
add.show();
}
}
},'-', {
text : "修改",
listeners : {
"click" : function() {
}
}
},'-',{
text:'刪除',
tooltip:'刪除記錄',
iconCls:'remove',
handler:handleDelete
}


],
bbar : new Ext.PagingToolbar({
displayInfo: true,

displayMsg: '顯示 {0} - {1} / {2}',
emptyMsg: '沒有數據',
store : store

})

});
store.load({params : {
start:0,
limit : 30
}
})
});



--------------------------------------------------js


public String deleteSalebill() {
try {
HttpServletRequest request = ActionContext.getActionContext().getRequest();
String choice[] = com.wutai.util.EasyStr.splitstring(request.getParameter("ids"));
System.out.println(request.getParameter("ids"));
System.out.println(choice[0]);
for(int i=0;i<choice.length;i++){
SalebillInfo tmpSalebillInfo = new SalebillInfo();
tmpSalebillInfo.setSalebillid(choice[i]);
salebillService.deleteSalebill(tmpSalebillInfo);
}

HttpServletResponse response = ActionContext.getActionContext().getResponse();


System.out.println(this.getSalebillid());
System.out.println(this.getCompanyid());
PrintWriter pw = response.getWriter();
response.getWriter().print("{success:true}");
return null;
} catch (Exception e) {
e.printStackTrace();
return "failure";
}
}


========================forbean

public String querySalebillPagedList(){
try {

HttpServletRequest request = ActionContext.getActionContext().getRequest();
HttpServletResponse response = ActionContext.getActionContext().getResponse();
//String page = request.getParameter("page");
Integer start=Integer.parseInt(request.getParameter("start"));
Integer limit=Integer.parseInt(request.getParameter("limit"));
String page=String.valueOf(start/limit+1);

//String firstquery = request.getParameter("firstQuery");
this.setSearchoption(true);

if (page.equals("1")) {

salebillPagedList = new PagedList();
salebillPagedList.setQueryName("browseSalebill");
request.getSession().removeAttribute(PagedList.NAME);
request.getSession().setAttribute(PagedList.NAME, salebillPagedList);
}else {
salebillPagedList = (PagedList) request.getSession().getAttribute(PagedList.NAME);
if (null == salebillPagedList|| !QUERY_NAME.equalsIgnoreCase(salebillPagedList.getQueryName())) {
logger.error("The query parameter is needed��");
return "failure";
}
}

salebillPagedList = (PagedList)request.getSession().getAttribute(PagedList.NAME);

//設置請求頁碼
salebillPagedList.setPage(Integer.parseInt(page));
//如果請求的記錄不在範圍內,就查詢數據庫。否則直接在PagedList對象裏取。
if (!salebillPagedList.exists(Integer.parseInt(page))) {
salebillService.getSalebillPagedList(salebillInfo, salebillPagedList);
}

response.setContentType("application/json;charset=UTF-8");
response.setCharacterEncoding("UTF-8");
PrintWriter pw = response.getWriter();
int total=salebillPagedList.getTotalNum();
String num=String.valueOf(total);
pw.write(Convert.objectcollect2json(salebillPagedList.getList(),num).toString());
//int num=salebillPagedList.getTotalNum();
//s=s.replaceAll(",\"start\":\\d*,\"totalNum\":\\d*,\"totalPage\":\\d*}","}");
//s=s.replaceAll("\"firstPage\":true,\"lastPage\":false,\"list","\"totalProperty\":"+num+",\"root");

return null;
} catch (Exception e) {
e.printStackTrace();
//ActionContext.getActionContext().addErrors("error.exception", e.toString());
return "failure";
}
}

----------------------------------forbean

package com.wutai.util;
import
net.sf.json.*;

import java.util.Map;
import java.util.HashMap;
import java.util.List;
public class Convert {
public static JSONObject generate(List list){

Map<String,Object> map = new HashMap<String, Object>();
map.put("totalProperty",list.size());
map.put("root", list);
return JSONObject.fromObject(map);
}
public static JSONObject javabean2json(Object object){
Map<String,Object> map = new HashMap<String, Object>();
map.put("success",true);
map.put("data",object);
return JSONObject.fromObject(map);
}

public static JSONObject objectcollect2json(List list,String total){
Map<String,Object> map = new HashMap<String, Object>();
map.put("totalProperty",total);
map.put("root",list);
return JSONObject.fromObject(map);
}
}

-------------------------方法
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章