zoukankan      html  css  js  c++  java
  • 使用EasyUI的Datagrid的Editor进行行编辑,Enter回车结束编辑,并开启新的一行。

    //新增数据
    function add() {

    if (Index == undefined) {
      row = { move_date: '', start_time: '', end_time: '', start_place: '', arrival_place: '', move_vehicle: '' };  
      $('#dg').datagrid('appendRow', row);
      Index = $('#dg').datagrid('getRows').length - 1;
      $('#dg').datagrid('selectRow', Index).datagrid('beginEdit', Index);
    }//新建行结束


    //回车时结束编辑,并开启新一行放在datagrid的onBeginEdit事件里

    onBeginEdit: function (Index, row) {

      var stayPlace = $("#dg_StaySchedule").datagrid('getEditor', { index: Index, field: 'stay_place' });
      var stayAmount = $("#dg_StaySchedule").datagrid('getEditor', { index: Index, field: 'stay_amount' });
      $(stayPlace.target).textbox('options').onChange = function (newValue, lodValue) {
      //开启等待
      MaskUtil.mask();
      $.ajax({//根据条件值获取数据
        type: "POST",
        url: "url?stay_place=" + newValue + "&emp_title=" + $('#emp_title').textbox('getValue'),
        dataType: 'json',
        success: function (msg) {
          //关闭等待
          MaskUtil.unmask();
          stayData = 0;
          stayData = JSON.parse(msg.stay);
          $(stayAmount.target).textbox('setValue', stayData);//查询的数据给列赋值
          }
        })
      }
      //回车时结束编辑,并开启新一行
      $('.datagrid-editable .textbox,.datagrid-editable .datagrid-editable-input,.datagrid-editable .textbox-text').bind('keypress', function (e) {
        var code = e.keyCode || e.which;
        f (code == 13) {
          //保存更改 第一次编辑可能不会改变值
          var b = $('#dg').datagrid('validateRow', Index);
          if (b == false) {
            $('#dg').datagrid('selectRow', Index).datagrid('beginEdit', Index);
            return;
            }
        $('#dg').datagrid('acceptChanges');
        $('#dg').datagrid('endEdit', Index);

        if (stayData > 0 && row.stay_amount > stayData) {
          $.messager.confirm('操作提示', "提交的住宿费已超标准费用,标准住宿费用是:" + stayData + "元,是否继续?", function (r) {
            if (r) {
              $('#dg').datagrid('unselectRow', Index);
              Index= undefined;          
              add();//新增方法
              }
          else {
            $('#dg').datagrid('beginEdit', Index);
            }
          })
        } else {

          Index= undefined;      
          add();//新增方法
          }
        }
      });
    }

  • 相关阅读:
    10、代码块、构造代码块、静态代码块及main方法之间的关系
    2.0、Hibernate框架的简单搭建
    1.0、Struts2的简单搭建方法
    5、Servlet的使用
    angular组件之间的通信
    angular项目中遇到的问题
    ng-zorro-mobile中遇到的问题
    angular管道操作符的使用
    angular路由配置以及使用
    搭建Angular环境
  • 原文地址:https://www.cnblogs.com/lijl/p/9759923.html
Copyright © 2011-2022 走看看