1. 程式人生 > >EasyUI datagrid 選擇單元格 出現文字框 修改 四

EasyUI datagrid 選擇單元格 出現文字框 修改 四

資料初始化

        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="width: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: '請款幣別', width: 100, 70 }, 71 { 72 field: 'RATE_VALUE', title: '匯率', width: 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>