Ext Grid实现增删改查的例子_ext grid 增删改-程序员宅基地

技术标签: ext  distance  string  null  Ext grid  function  header  

  一:new Ext.grid.EditorGridPanel实现行内增删改查
var stationLineStore=new Ext.data.JsonStore({
        url:"../../../addByShowStationLine.do?lineCode="+myCjxx.lineCode, // 数据源
           fields:[ 'stationCode', 'stationName', 'stationNumcode','distance']
          });
var stationStore = new Ext.data.JsonStore({
        url:"../../../showStationByCjId.do?cjId="+myCjxx.cjId, // 数据源
        fields:['cjId','stationName','stationCode','distance','stationId']
   });
stationStore.load();
var stationCj = Ext.data.Record.create([
                                {name:"cjId",type:"string"},
                                {name:"stationName",type:"string"},
                                {name:"distance",type:"int"},
                                {name:"stationCode",type:"string"},
                                {name:"stationId",type:"string"}
                           ]);
//车站
var stationCm = new Ext.grid.ColumnModel(
         [
             new Ext.grid.RowNumberer(), {
              header : "",
              id:"stationId",
                 dataIndex: 'stationId',
     hidden : true,
               },
             {
                 header   : '车站名称',
                 width    : 60,
                 sortable : true,
                 dataIndex: 'stationName',
                 editor:new Ext.form.ComboBox({
               allowBlank: false,
               id:'stationLine',
               triggerAction:  'all',
               forceSelection: true,
               editable:       false,//只能选 不能输入
               displayField:   'stationName',
                        valueField:     'stationCode',
                        store:stationLineStore,
                        listeners:{
                         "select":function(com,record,index){
                        var currentGird = Ext.getCmp("grid1");
                        var num = currentGird.getSelectionModel().lastActive;//行号
                       
                       var curGridRe=stationStore.getAt(num);
                     
                       
                            curGridRe.set("stationCode",record.get('stationCode'));//设置
                            curGridRe.set("stationName",record.get('stationName'));//设置
                            curGridRe.set("distance",record.get('distance'));
                            curGridRe.set("stationNumcode",record.get('stationNumcode'));
                         
                         }
                        }
           }),
           renderer: function(value, cellmeta, record) {
           
            var index = stationLineStore.find(Ext.getCmp('stationLine').valueField,value);
            var tempRecord = stationLineStore.getAt(index);
          
            var displayText = "";
            if (record == null || tempRecord == null) {
               displayText = value;
            } else {
               displayText = tempRecord.get("stationName");
            }
            record.set("stationName",displayText);
           
            return displayText;
                  }// */
             },
             {
                 header   : '距离',
                 width    : 60,
                 sortable : true,
                 dataIndex: 'distance'
             }
         ]
     );
var stationGrid = new Ext.grid.EditorGridPanel({
        store: stationStore,
        id:'grid1',
        sm : sm,
  cm : stationCm,
        stripeRows: true,
        height: 100,
        clicksToEdit:2,
        autoWidth:true,
        autoScroll: true,
        title:"场景车站",
        viewConfig: {
            forceFit: true
        },
        tbar:[{ 
             text : '删除', 
             iconCls:'silk-delete', 
             handler : function(src) { 
      
              var rows = stationGrid.getSelectionModel().getSelections();//返回的是数组
              if(rows.length==0){
               Ext.MessageBox.alert("警告","最少选择一条信息,进行删除!");
              }else{
               Ext.MessageBox.confirm("提示框","您确定要删除选择的信息?",function(btn){
                if(btn=="yes"){
                 var json = new Array();
                 for(var i = 0, r; r = rows[i]; i++){
                  var js = {};
                 js.cjId = r.get('cjId');
                 js.stationId=r.get('stationId');
                 json.push(js);
                       }
              
                Ext.Ajax.request({
                    url:'../../../deleteStationCj.do',
                    params:{json:"["+_ToJSON(json)+"]"},
                    success:function(res,op){
                      var result = Ext.util.JSON.decode(res.responseText);
                      if(result.deletes==true){
                       Ext.MessageBox.alert("提示","删除成功");
                       stationStore.reload();
                      }else{
                       Ext.MessageBox.alert("提示","删除失败");
                       return;
                      }
                    },
                    failure:function(res,op){
                      var result = Ext.util.JSON.decode(res.responseText);
                       if(result.deletes==false){
                        Ext.MessageBox.alert("提示","可能存在主外键关系");
                        return;
                       }
                    }
                   });
                }
               });
               //对话框结束
              }
             
             }
          },{ 
                   text : '新增', 
                   iconCls:'silk-add', 
                   handler : function(btn, ev) {
            
                 var c= new stationCj({
                  cjId:myCjxx.cjId,
                 stationName:'',
                 stationId:0,
                 stationCode:"",
                  distance:0
                       });
                 var curenStoreCount=stationGrid.getStore().getCount();
                 stationGrid.stopEditing();
                 stationStore.insert(curenStoreCount,c);
                 stationGrid.getSelectionModel().selectRow(curenStoreCount);
                 stationGrid.startEditing(curenStoreCount,2);
                  }
                },
                { 
                    text : '保存', 
                    iconCls:'icon-save', 
                    handler : function(btn, ev) {
                     var rows = stationGrid.getSelectionModel().getSelections();//返回的是数组
                   if(rows.length==0||rows.length>1){
                   Ext.MessageBox.alert("警告","选择一条信息,进行保存!");
                   }else{
                    var selectRow= stationGrid.getSelectionModel().lastActive;
                      var r = stationGrid.getStore().getAt(selectRow);//获取当前选中行的record
                   
                   var json = {};
                   json.cjId=r.get('cjId');
                   json.stationName=r.get("stationName");
                   json.stationId=r.get('stationId');
                   json.lineCode = myCjxx.lineCode;
                  json.distance=r.get("distance");
                  json.stationCode=r.get("stationCode");
                     json.stationNumcode=r.get("stationNumcode");
                   if(json.stationId==0){//为0时时新增
                    json.lineName = myCjxx.lineName;
                   }
                   if( json.stationName==""){
                    Ext.MessageBox.alert("警告","信息不能为空!");
                    return;
                   }
                  
                   Ext.Ajax.request({
                      url:'../../../addOrUpdateStationCj.do',
                      params:{json:_ToJSON(json)},
                      success:function(res,op){
                        var result = Ext.util.JSON.decode(res.responseText);
                        if(result.success==true&&result.add==1){
                         Ext.MessageBox.alert("提示","添加成功");
                         stationStore.reload();
                        }else if(result.success==true&&result.add==2){
                         Ext.MessageBox.alert("提示","修改成功");
                         stationStore.reload();
                        }else{
                        
                           var isAdd="";
                                              if(json.stationId==0){
                                               stationGrid.store.removeAt(selectRow);//删除行
                                                isAdd="添加";
                                              }else{
                                               isAdd="修改";
                                               stationStore.reload();
                                              }     
                                              Ext.MessageBox.alert("提示","该信息已经存在"+isAdd+"失败");
                         return;
                        }
                      },
                      failure:function(res,op){
                        var result = Ext.util.JSON.decode(res.responseText);
                         if(result.success==false){
                          Ext.MessageBox.alert("提示","添加或修改失败");
                          if(json.stationId==0){
                           stationGrid.store.removeAt(selectRow);//删除行
                                              }else{
                                               stationStore.reload();
                                              }   
                          return;
                         }
                      }
                     });
                   
                   
                   }
             }
                  
          }
          ]
       
    });
二:new Ext.grid.GridPanel实现
  var zkxxProxy = new Ext.data.HttpProxy({
      api:{
       read:"../../../loadZhekouxinxiController.do?cjslId="+changjingSlId,
       create: '../../../updateZhekouxxController.do'   //添加和修改是同一个url
      }
     });
  var zkxxReader = new Ext.data.JsonReader({root:"zhekouXx"},
             [
              {name:'cjslId',type:'string'},
              {name: 'isZhekou',type:'string'},
                                                {name: 'isZhekouValue',type:'string'},
                                                {name: 'trainClassName',type:'string'},
                                                {name: 'trainClass',type:'string'},
                                                {name: 'seatTypeName',type:'string'},
                                                {name: 'seatType',type:'string'},
                                                {name: 'zhekouLv',type:'string'},
                                                {name: 'lieche',type:'string'},
                                                {name: 'liecheValue',type:'string'}
                                                 ]);
 
  var zkxxRecord = Ext.data.Record.create([{
   name:'cjslId',
   type:'string'
  },{
   name:'isZhekou',
   type:'string'
  },{
   name:'isZhekouValue',
   type:'string'
  },{
   name:'trainClassName',
   type:'string'
  },{
   name:'trainClass',
   type:'string'
  },{
   name:'seatTypeName',
   type:'string'
  },{
   name:'seatType',
   type:'string'
  },{
   name:'zhekouLv',
   type:'string'
  },{
   name:'lieche',
   type:'string'
  },{
   name:'liecheValue',
   type:'string'
  }]);
  // */
  var zkxxWriter = new Ext.data.JsonWriter({
   encode: true,
   writeAllFields: false
  });
  var zkxxDes = new Ext.data.GroupingStore({
   proxy: zkxxProxy,
         reader: zkxxReader,
         autoLoad:true,
         writer: zkxxWriter
     });
  // zkxxDes.load();
  var zkxxEdit = new Ext.ux.grid.RowEditor({
   saveText: '保存', 
   cancelText:'取消',
   listeners: {
          afteredit: function(){
     Ext.getCmp("youwuZhekouId").setDisabled(true);
     Ext.getCmp("liecheJibieId").setDisabled(true);
     Ext.getCmp("zuoweiZhongleiId").setDisabled(true);
     Ext.getCmp("zheKouFanweiId").setDisabled(true);
    },
    canceledit:function(){
     Ext.getCmp("youwuZhekouId").setDisabled(true);
      Ext.getCmp("liecheJibieId").setDisabled(true);
      Ext.getCmp("zuoweiZhongleiId").setDisabled(true);
      Ext.getCmp("zheKouFanweiId").setDisabled(true);
      var s = zkxxGrid.getSelectionModel().getSelections();
            for(var i = 0, r; r = s[i]; i++){
            if(r.data.zhekouLv==""&&r.data.trainClassName=="")
             zkxxDes.remove(r);
            }
    }
  }
    });
 
  var zhekouStore = new Ext.data.JsonStore({
            fields : ['isZhekou', 'isZhekouValue'],
            data   : [
                     
                {isZhekou : '有',   isZhekouValue: '1'},
                {isZhekou : '无',   isZhekouValue: '0'}
            ]
        })
 
  var liecheFanweiStore =  new Ext.data.JsonStore({
             fields : ['lieche', 'liecheValue'],
             data   : [
                 {lieche : '所有列车',   liecheValue: '0'},
                 {lieche : '部分列车',   liecheValue: '1'}
             ]
         })
 
  var zkxxCm = new Ext.grid.ColumnModel({
        defaults: {
            sortable: true      
        },
        columns: [
                {
                 dataIndex:"cjslId",
                 hidden:true
                },
                     {
             header: '有无折扣',
             dataIndex:'isZhekouValue',
             editor: new fm.ComboBox({
                 allowBlank: false,
                 id:'youwuZhekouId',
                 disabled:true,
                 mode:           'local',
                 triggerAction:  'all',
                 forceSelection: true,
                 editable:       false,
                 displayField:   'isZhekou',
                          valueField:     'isZhekouValue',
                          store:    zhekouStore     
             }),
             renderer: function(value, cellmeta, record) {
             var index = zhekouStore.find(Ext.getCmp('youwuZhekouId').valueField,value);
             var tempRecord = zhekouStore.getAt(index);
             var displayText = "";
             if (record == null || tempRecord == null) {
                displayText = value;
             } else {
                displayText = tempRecord.get("isZhekou");
             }
             record.set("isZhekou",displayText);
             return displayText;
                   }// */
                     },
               {
                 header: '列车级别',
                 dataIndex:'trainClass',
                 editor: new fm.ComboBox({
                  allowBlank: false,
                  id:'liecheJibieId',
                  disabled:true,
                  triggerAction:  'all',
                  forceSelection: true,
                  editable:       false,
                  displayField:   'trainClassName',
                           valueField:     'trainClass',
                           store:liecheLvStore
              }),
              renderer: function(value, cellmeta, record) {
              var index = liecheLvStore.find(Ext.getCmp('liecheJibieId').valueField,value);
              var tempRecord = liecheLvStore.getAt(index);
              var displayText = "";
              if (record == null || tempRecord == null) {
                 displayText = value;
              } else {
                 displayText = tempRecord.get("trainClassName");
              }
              record.set("trainClassName",displayText);
              return displayText;
                    }// */
                     },
               {
                 header: '座位种类',
                 dataIndex:'seatType',
                 editor: new fm.ComboBox({
                  allowBlank: false,
                  id:'zuoweiZhongleiId',
                  disabled:true,
                  triggerAction:  'all',
                  forceSelection: true,
                  editable:       false,
                  displayField:   'seatTypeName',
                           valueField:     'seatType',
                           store:zuoweiTypeStore
              }),
              renderer: function(value, cellmeta, record) {
              var index = zuoweiTypeStore.find(Ext.getCmp('zuoweiZhongleiId').valueField,value);
              var tempRecord = zuoweiTypeStore.getAt(index);
              var displayText = "";
              if (record == null || tempRecord == null) {
                 displayText = value;
              } else {
                 displayText = tempRecord.get("seatTypeName");
              }
              record.set("seatTypeName",displayText);
              return displayText;
                    }// */
                     },
                     {
                      header: '折扣等级',
                      dataIndex:'zhekouLv',
                      editor:new fm.TextField({
                      
                      })
                     },
                     {
              header: '折扣列车范围',
              dataIndex:'liecheValue',
              editor: new fm.ComboBox({
                  id:'zheKouFanweiId',
                  allowBlank: false,
                  disabled:true,
                  mode:           'local',
                  triggerAction:  'all',
                  forceSelection: true,
                  editable:       false,
                  displayField:   'lieche',
                           valueField:     'liecheValue',
                           store:  liecheFanweiStore      
              }),
              renderer: function(value, cellmeta, record) {
              var index = liecheFanweiStore.find(Ext.getCmp('zheKouFanweiId').valueField,value);
             
              var tempRecord = liecheFanweiStore.getAt(index);
              var displayText = "";
              if (record == null || tempRecord == null) {
                 displayText = value;
              } else {
                 displayText = tempRecord.get("lieche");
              }
              record.set("lieche",displayText);
              return displayText;
                    }// */
                      }
                     ]
 
  });
   var zkxxGrid = new Ext.grid.GridPanel({
          store: zkxxDes,
          cm: zkxxCm,
          plugins: [zkxxEdit],
          frame: true,
          height: 180,
          title: '折扣信息',
          tbar: [{
              text: '添加',
              iconCls: 'silk-add',
              handler: onAddZhekouInfo
          }, '-'
          , { text: '删除',
           iconCls: 'silk-delete',
           handler:onDeleteZhekouInfo },
          '-'],
          viewConfig: {
              forceFit: true
          }
        
   });
 
   function onAddZhekouInfo(btn, ev) {
    Ext.getCmp("youwuZhekouId").setDisabled(false);
    Ext.getCmp("liecheJibieId").setDisabled(false);
    Ext.getCmp("zuoweiZhongleiId").setDisabled(false);
    Ext.getCmp("zheKouFanweiId").setDisabled(false);
    var zk= new zkxxRecord({
     cjslId:changjingSlId,
     isZhekou:'',
     isZhekouValue:'',
     trainClassName:'',
     trainClass:'',
     seatTypeName:'',
     seatType:'',
     zhekouLv:'',
     liecheValue:''
          });
    zkxxEdit.stopEditing();
    zkxxDes.autoSave=false;
    zkxxDes.insert(0,zk);
    zkxxDes.autoSave=true;
    zkxxGrid.getView().refresh();
    zkxxGrid.getSelectionModel().selectRow(0);
    zkxxEdit.startEditing(0);
      }
   function onDeleteZhekouInfo(btn, ev) {
    zkxxEdit.stopEditing();
          var s = zkxxGrid.getSelectionModel().getSelections();
          for(var i = 0, r; r = s[i]; i++){
            $.post("../../../deleteZhekouxinxiController.do",{cjslId:r.data.cjslId,zuoweizhonglei:r.data.seatType,liechejibie:r.data.trainClass},function(result){
             if(result>0){
              Ext.Msg.alert('状态', '删除成功');
              zkxxDes.remove(r);
             }else{
              Ext.Msg.alert('状态', '删除失败请重试');
             }
            })
           }
      }
      // */
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/liushuli81/article/details/7382839

智能推荐

chatglm2-6b-int4大语言模型家用电脑部署-程序员宅基地

文章浏览阅读1k次。ChatGLM-6B 是一个开源的、支持中英双语问答的对话语言模型,基于架构,具有 62 亿参数。结合模型量化技术,用户可以在消费级的显卡上进行本地部署(INT4 量化级别下最低只需 6GB 显存)。ChatGLM-6B 使用了和ChatGLM相同的技术,针对中文问答和对话进行了优化。经过约 1T 标识符的中英双语训练,辅以监督微调、反馈自助、人类反馈强化学习等技术的加持,62 亿参数的 ChatGLM-6B 已经能生成相当符合人类偏好的回答。_chatglm2-6b-int4

Linux启动重启mysql_linux mysql启动-程序员宅基地

文章浏览阅读6.4k次,点赞3次,收藏7次。一、启动方式1、使用linux命令service 启动:service mysqld start2、使用 mysqld 脚本启动:/etc/inint.d/mysqld start3、使用 safe_mysqld 启动:safe_mysqld&一、重启1、使用linux命令service 重启:service mysqld restart2、使用 mysqld 脚本重启:/etc/inint.d/mysqld restart二、停止 1、使用 service 启动: se._linux mysql启动

字典序全排列题解(Java实现,以北京大学考研机试题为例)_java字典序全排列代码解析-程序员宅基地

文章浏览阅读1k次。文章目录题目分析(需要结合我之前上一篇全排列文章来看)代码实现运行结果题目分析(需要结合我之前上一篇全排列文章来看)在之前全排列的文章进行进一步理解之前的文章全排列是只交换起始位置和待排在第一位的元素进行互换,而其他元素不变,待第一趟全排列之后再回溯之前交换的元素位置。而这次题目要求的字典序全排列则是多了一个需求,即是在交换的起始元素位置和待交换元素的位置之间数组依次左移,相对应在一次排列后就要换成右移。代码实现import java.util.*;public class Main{ _java字典序全排列代码解析

HBase启动后查询报错:ERROR: org.apache.hadoop.hbase.PleaseHoldException: Master is initializing-程序员宅基地

文章浏览阅读2.2k次,点赞2次,收藏7次。HBase启动后查询报错:ERROR: org.apache.hadoop.hbase.PleaseHoldException: Master is initializing_error: org.apache.hadoop.hbase.pleaseholdexception: master is initializing

SqlServer日期时间函数,最全_sqlserver中如何判断一个时间是另一个时间的下个月-程序员宅基地

文章浏览阅读9.9k次,点赞3次,收藏45次。datediff(day,createdate,GetDate())=0 -- 判断是否当天,createdate为日期字段第一天、第几月-- 1.一个月第一天的Select DATEADD(mm, DATEDIFF(mm,0,getdate()), 0)-- 2.本周的星期一Select DATEADD(wk, DATEDIFF(wk,0,getdate()), 0)-- 3.一年的第一天Select DATEADD(yy, DATEDIFF(yy,0..._sqlserver中如何判断一个时间是另一个时间的下个月

Numpy常用random随机函数_numpy random-程序员宅基地

文章浏览阅读5.8k次,点赞7次,收藏35次。只要random.seed( * ) seed里面的值一样,那随机出来的结果就一样。所以说,seed的作用是让随机结果可重现。也就是说当我们设置相同的seed,每次生成的随机数相同。如果不设置seed,则每次会生成不同的随机数。使用同一个种子,每次生成的随机数序列都是相同的。_numpy random

随便推点

Java程序员学算法(3) - 梯度提升决策树(Gradient Boosting Decision Tree)_java经验上升梯度算法-程序员宅基地

文章浏览阅读483次,点赞2次,收藏3次。本篇继续进阶一点,写一下 梯度提升决策树(Gradient Boosting Decision Tree),详细解释可参考https://www.jianshu.com/p/005a4e6ac775的第三部分还是先上代码,梯度提升决策树是能够支持多种损失函数的,关于损失函数的定义,老规矩,自己搜。既然要支持多种损失函数,因此先写个接口类,然后再来个实现,后面会用到损失函数接口..._java经验上升梯度算法

EM算法-硬币实验的理解_em方法解决双硬币问题的思路-程序员宅基地

文章浏览阅读3.4k次,点赞6次,收藏27次。EM算法-使用硬币实验的例子理解EM算法,即最大期望算法(Expectation-Maximization algorithm, EM),是一类通过迭代进行极大似然估计(Maximum Likelihood Estimation, MLE)的优化算法 ,通常作为牛顿迭代法的替代用于对包含隐变量(latent variable)或缺失数据(incomplete-data)的概率模型进行参数估..._em方法解决双硬币问题的思路

关于阅读理解,我们学的,都是错的-程序员宅基地

文章浏览阅读552次。本文的内容,年轻人如何提高职场视野其实这里提到了一些,很多旧文也都断断续续提过,今天整理一下。我们中学学阅读理解,总结文章中心内容,把握作者意图,理解文章要旨,大家都是..._关于阅读理解 我们学的都是错的

IBM大数据分析 算出来的“赛点”-程序员宅基地

文章浏览阅读160次。  对某位球员的成长历史烂熟于心,了解每场重要赛事的比赛得分,获胜球队。我相信这是我们眼中资深球迷应该具备的素质。然而如果我问你,这场比赛你支持的那支球队的控球率是多少?进球率又是多少?有几次抢断?几脚射门?几次射在门里,几次射在门外。对于这些数据,我想单凭人脑,恐怕是做不到了。通常这..._ibm slamtracker算法

Linux线程同步(5)——互斥锁or自旋锁?_linux自旋锁和互斥锁-程序员宅基地

文章浏览阅读469次。自旋锁与互斥锁很相似,从本质上说也是一把锁,在访问共享资源之前对自旋锁进行上锁,在访问完成后释放自旋锁(解锁);事实上,从实现方式上来说,互斥锁是基于自旋锁来实现的,所以自旋锁相较于互斥锁更加底层。如果在获取自旋锁时,自旋锁处于未锁定状态,那么将立即获得锁(对自旋锁上锁);如果在获取自旋锁时,自旋锁已经处于锁定状态了,那么获取锁操作将会在原地“自旋”,直到该自旋锁的持有者释放了锁。由此介绍可知,自旋锁与互斥锁相似,但是互斥锁在无法获取到锁时会让线程陷入阻塞等待状态;_linux自旋锁和互斥锁

【小程序】快来开发你的第一个微信小游戏(详细流程)_微信小游戏开发-程序员宅基地

文章浏览阅读7.5w次,点赞145次,收藏787次。本文通过开发一个简单的小游戏,来带领大家实操一下开发小游戏的基本流程。快来和博主一起操作吧!!!_微信小游戏开发