EasyUI datagrid 选择单元格 出现文本框 修改 四

@disabled = "disabled", 只读属性

数据初始化

        public JsonResult RateList(string dispatch_number, string target_currency)
        {
            var product = new[]
            {
                new { REQUEST_FUNDS_CURRENCY ="RMB" ,RATE_VALUE="2.32"},
                new { REQUEST_FUNDS_CURRENCY ="RMB1" ,RATE_VALUE="2.12"},
                new { REQUEST_FUNDS_CURRENCY ="RMB2" ,RATE_VALUE="2.34"},
            };
            return Json(new { total = product.Count(), rows = product }, JsonRequestBehavior.AllowGet);
        }

  

  1 <link href="~/Content/easyui.css" rel="stylesheet" />
  2 <link href="~/Content/icon.css" rel="stylesheet" />
  3 <script src="~/Scripts/jquery-1.10.2.min.js"></script>
  4 <script src="~/Scripts/jquery.easyui.min.js"></script>
  5 
  6 <div style="300px; height:350px;">
  7     <button  id="qq" >dfsd</button>
  8     <table id="Cse_Bespeak_Log" ></table>
  9     </div>
 10     <script type="text/javascript">
 11         $('#qq').click(function () { //保存的时候 最后 一个框还没完成 修改
 12             if (endEditCal()) {
 13                 console.log(1);
 14             }
 15 
 16         });
 17         var RATE_VALUE;
 18         $.extend($.fn.datagrid.methods, {
 19             beginEditCell: function (jq, param) {
 20                 return jq.each(function () {
 21                     var opts = $(this).datagrid('options');
 22                     var fields = $(this).datagrid('getColumnFields', true).concat($(this).datagrid('getColumnFields'));
 23                     for (var i = 0; i < fields.length; i++) {
 24                         var col = $(this).datagrid('getColumnOption', fields[i]);
 25                         col.editor1 = col.editor;
 26                         if (fields[i] != param.field) {
 27                             col.editor = null;
 28                         }
 29                     }
 30                     $(this).datagrid('beginEdit', param.index);
 31                     for (var i = 0; i < fields.length; i++) {
 32                         var col = $(this).datagrid('getColumnOption', fields[i]);
 33                         col.editor = col.editor1;
 34                     }
 35                 });
 36             }
 37         });
 38         var editIndex = -1;
 39         function endEditCal() {
 40             if (editIndex == -1) {
 41                 return true;
 42             }
 43             if ($('#Cse_Bespeak_Log').datagrid('validateRow', editIndex)) {
 44                 $('#Cse_Bespeak_Log').datagrid('endEdit', editIndex);
 45                 editIndex = -1;
 46                 return true;
 47             }
 48             else {
 49                 return false;
 50             }
 51         }
 52         $("#Cse_Bespeak_Log").datagrid({
 53             url: "@Url.Action("RateList")",
 54             queryParams: {
 55                 dispatch_number: "234234",
 56                 target_currency: "2323",
 57             },
 58             loadMsg: "数据加载中......",
 59             rownumbers: true,
 60             autoRowHeight: false,
 61             fit: true,
 62             fitColumns: false,
 63             striped: true,
 64             singleSelect: true,
 65             collapsible: false,
 66             pagination: false,
 67             columns: [[
 68                 {
 69                     field: 'REQUEST_FUNDS_CURRENCY', title: '请款币别',  100,
 70                 },
 71                 {
 72                     field: 'RATE_VALUE', title: '汇率',  150,
 73                     editor: { type: 'text', },
 74                     styler: function (value, row, index) {
 75                         return 'background-color:#ecffff;';
 76                     },
 77                 }]],
 78             onClickCell: function (index, field, value) { //编辑一个单元格
 79                 if (endEditCal()) {
 80                     $(this).datagrid('selectRow', index).datagrid('beginEditCell', { index: index, field: field }); //编辑一个单元格
 81                     //$(this).datagrid('beginEdit', index); //编辑一行
 82                     RATE_VALUE = $(this).datagrid("getRows")[index].RATE_VALUE;
 83                     editIndex = index;
 84                 }
 85                 else {
 86 
 87                 }
 88             },
 89             onAfterEdit: function (index, row, changes) {//改变后触发
 90                 console.log(changes.RATE_VALUE);
 91                 if(changes.RATE_VALUE<0)
 92                 {
 93                     $('#Cse_Bespeak_Log').datagrid('updateRow', {
 94                         index: index,
 95                         row: {
 96                             RATE_VALUE: 0
 97                         },
 98                     });
 99                 }
100             }
101 
102         });
103 
104     </script>
原文地址:https://www.cnblogs.com/LiuFengH/p/9808548.html