extjs做的添加,删除给大家分享一下.加载数据的数据

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<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);
           }
   }

-------------------------方法





你可能感兴趣的:(ExtJs)