EXT JS

 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri=" http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
  <head>
    <base href="<%=basePath%>">
    <title>EXTJS分页DEMO</title>
 <meta http-equiv="pragma" content="no-cache">
 <meta http-equiv="cache-control" content="no-cache">
 <meta http-equiv="expires" content="0">   
 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
 <meta http-equiv="description" content="This is my page">
 <link type="text/css" rel="stylesheet" href="<%=basePath%>plug-in/ext-2.2/resources/css/ext-all.css" />
 <script type="text/javascript" src="<%=basePath%>plug-in/ext-2.2/adapter/ext/ext-base.js"></script>
 <script type="text/javascript" src="<%=basePath%>plug-in/ext-2.2/ext-all.js"></script>
 <style type="text/css">
  .testCss{
   font-size: 12px;
   font-family:宋体;
   font-weight:bold;
   color: #000066;
  }
  .add .x-btn-text{
   background-image:url("<%=basePath%>images/add.gif");
  }
  .del .x-btn-text{
   background-image:url("<%=basePath%>images/forbidden.gif");
  }
  .update .x-btn-text{
   background-image:url("<%=basePath%>images/save.gif");
  }
 </style>
 <script type="text/javascript">
  Ext.onReady(function(){
  
  });
  function createInfoTab(){
   var win;
   var modWin;
   var modForm;
   // checkbox选中模式
   var sm = new Ext.grid.CheckboxSelectionModel();
   // sm.on('rowdeselect',delRec(sm));
   // sm.on('rowselect',function(sm){delRec(sm);});
   sm.handleMouseDown = Ext.emptyFn;
   // sm.addListener("click",delRec,null,null);
   // 列模型
   var cm = new Ext.grid.ColumnModel([
    // 列数字
   //    new Ext.grid.RowNumberer(),
       // checkbox
       sm,
       // 表头
       {header:'<b class="testCss">编号</b>',dataIndex:'userid',sortable:true,css:'font-size:12px;color:black;font-family:宋体;',hidden:true},
          {header:'<b class="testCss">工号</b>',dataIndex:'usercode',sortable:true,css:'font-size:12px;color:black;font-family:宋体;'},
          {header:'<b class="testCss">姓名</b>',dataIndex:'username',sortable:true,css:'font-size:12px;color:black;font-family:宋体;'},
          {header:'<b class="testCss">班</b>',dataIndex:'classname',sortable:true,css:'font-size:12px;color:black;font-family:宋体;'},
          {header:'<b class="testCss">组</b>',dataIndex:'groupname',sortable:true,css:'font-size:12px;color:black;font-family:宋体;'}
    ]);
   // 默认排序
      cm.defaultSortable = true;
    var ds = new Ext.data.Store({
          proxy: new Ext.data.HttpProxy({url:'<%=basePath%>splitpage.do'}),
          reader: new Ext.data.JsonReader({
                  totalProperty: 'totalProperty',
                  root: 'root'
      },
      [
       {name: 'userid',mapping:'userid'},
          {name: 'usercode',mapping:'usercode'},
          {name: 'username',mapping:'username'},
          {name: 'classname',mapping:'classname'},
          {name: 'groupname',mapping:'groupname'}
      ])
      // 不排序
      // remoteSort:true
      });
     var grid = new Ext.grid.GridPanel({
       el: 'grid1',
       draggable: false,
       title:'<b style="font-family:宋体;font-size:14px;">班组列表</b>',
       width:720,
       height:540,
       trackMouseOver:false,
       loadMask: {msg:'正在加载数据,请稍侯……'},
       store:ds,
       cm: cm,
       disabled:false,
       sm:sm,
       bbar: new Ext.PagingToolbar({
               pageSize: 20,
               store: ds,
               displayInfo: true,
               emptyMsg:'没有记录',
               displayMsg: '当前显示 {0} - {1}条记录 /共 {2}条记录',
               emptyMsg: "No topics to display"
           }),
      tbar: [
        {text:'<p style="font-family:宋体;font-size:12px;">添加</p>',cls:'x-btn-text-icon add',tooltip:'Add a new row',
         handler:function(){
       if(!win){
        var simple = new Ext.form.FormPanel({
         labelWidth: 35, // label settings here cascade unless overridden
          url:'<%=basePath%>addUsers.do?method=add',
         method:'POST',
         frame:true, 
         bodyStyle:'padding:5px 5px 0',
         width: 300,
         defaults: {width:200},
         defaultType: 'textfield',
         // /实现非AJAX提交表单一定要加下面的两行!
         // onSubmit:function(){alert("sdf");},
         //submit: function() {
          //有疑问的地方
          //this.getEl().dom.action='<%=basePath%>addUsers.do';
          //this.getEl().dom.submit();
         //},
         items: [{
          fieldLabel: '工号',
          id: 'usercode',
          allowBlank:false
         },{
          fieldLabel: '姓名',
          id: 'username',
          allowBlank:false
         }
         ],
         buttons: [{
          text: '<p style="font-family:宋体;font-size:12px;">添加</p>',
          type:'button',
          id:'login',
          handler: function(){
            simple.getForm().submit({
             method:'POST',
             waitMsg:'正在保存数据...',
             success:function(form,action){
              this.disabled=false;
              form.reset();
              alert('保存成功!');  
                                         win.hide();
              ds.load({params:{start:0, limit:20}});
              grid.getView().refresh();
             },
             failure:function(){
              alert('保存失败!');
             }
            });
           }
          },{
          text: '<p style="font-family:宋体;font-size:12px;">重置</p>',
          type:'reset',
          id:'clear',
          handler: function(){simple.getForm().reset();}
          }
          ]
        });
        win = new Ext.Window({
         layout:'fit',
         width:300,
         title:'<p style="font-family:宋体;font-size:12px;">添加坐席</p>',
         height:150,
         closeAction:'hide',
         plain:true,
         buttonAlign:'center'
        }); 
        win.add(simple);     
       }
       win.show(this);
      }
        },
        {text:'<p style="font-family:宋体;font-size:12px;">修改</p>',cls:'x-btn-text-icon update',tooltip:'Add a new row',
         handler:function(){
          var rec = grid.getSelections();
          if(rec.length>1){
           alert("一次只能选择一跳要修改的记录");
           return;
          }
          if(rec.length<1){
           alert("请选择一跳您要修改改的记录");
           return;
          }
          var userid = rec[0].get("userid");
          var usercode = rec[0].get("usercode");
          var username = rec[0].get("username");
          if(!modForm){
           modForm = new Ext.form.FormPanel({
            labelWidth: 35, // label settings here cascade unless overridden
          url:',
         method:'POST',
         frame:true, 
         disabled:false,
         bodyStyle:'padding:5px 5px 0',
         width: 300,
         defaults: {width:200},
         defaultType: 'textfield',
         reader:new Ext.data.JsonReader({  
                            root: 'rows',  
    //                      totalProperty: 'total',  
                            success:true,  
                           fields: [  
                                 'userid','usercode','username' 
                                ]  
                            }  
                         ),  
         items: [{
          fieldLabel: '编号',
          id: 'userid',
          allowBlank:false
         },{
          fieldLabel: '工号',
          id: 'usercode1',
          allowBlank:false
         },{
          fieldLabel: '姓名',
          id: 'username1',
          allowBlank:false
         }],
         buttons: [{
          text: '<p style="font-family:宋体;font-size:12px;">修改</p>',
          type:'button',
          id:'modify',
          handler: function(){
            modForm.getForm().submit({
             method:'POST',
             waitMsg:'正在保存数据...',
             success:function(form,action){
              form.reset();
              modWin.hide();
              alert('修改成功!');  
              ds.reload();
              grid.getView().refresh();
             },
             failure:function(){
              alert('修改失败!');
             }
            });
           }
          },{
          text: '<p style="font-family:宋体;font-size:12px;">重置</p>',
          type:'reset',
          id:'clear',
          handler: function(){modForm.getForm().reset();}
          }
         ]
           });
          }
          if(!modWin){
           modWin = new Ext.Window({
            layout:'fit',
         width:300,
         title:'<p style="font-family:宋体;font-size:12px;">修改坐席</p>',
         height:170,
         closeAction:'hide',
         plain:true,
         buttonAlign:'center'
           });
           modWin.add(modForm);
          }
          modWin.show(this);
          // 只有form被显示后才有值
          modForm.getForm().findField("userid").setValue(userid);
          modForm.getForm().findField("usercode1").setValue(usercode);
          modForm.getForm().findField("username1").setValue(username);
         }
        },
        {text:'<p style="font-family:宋体;font-size:12px;">删除</p>',cls:'x-btn-text-icon del',tooltip:'Add a new row',
         handler:function(){
          var ids = "";
          var rec = grid.getSelections();
          for(var i = 0 ; i < rec.length ; i ++ ){
        ids += rec[i].get("userid")+",";
       }
       if(ids.indexOf(",")!=-1){
        ids = ids.substring(0,ids.length-1);
       }
       if(ids==""){
        alert("请选择您要删除的记录");
        return;
       }
          if(window.confirm("您确定要删除吗?")){
           Ext.Ajax.request({
          url:',
         method:'POST',
         params: {ids:ids,method:'del'},  
            callback: function(options, success, response) {  
                alert("删除成功");
                ds.reload();
                grid.getView().refresh();
                // Ext.Msg.alert("提示","删除成功");
                // 回调函数
            }  
        });
          }
         }
        }
        ]  
      }); 
     ds.load({params:{start:0, limit:20}});
     grid.render();
  }
  window.onload = function(){
   createInfoTab();
  }
 </script>
  </head>
  <body>
  <div id="grid1"></div>
  </body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值