jQuery MiniUI

 找回密码
 立即注册
查看: 3542|回复: 13
打印 上一主题 下一主题

CellEdit的一个问题,求指教 [复制链接]

Rank: 1

跳转到指定楼层
楼主
发表于 2014-4-23 11:32:45 |只看该作者 |倒序浏览
需求是这样的 首先每个单元格的值都是数字编辑  列1  列2   然后跟据自定义的算法 自动填充  列3  列4  列5   
此时没有问题  然后   修改 列3 需要 列4 列5 的值根据算法改变值
这时问题出现  进去到 列4 列5 的编辑器中时显示的是已经改变的值 按下回车进入下一个单元格编辑时  列4 列5 中的值却显示计算前的值
这是怎么回事呢?

Rank: 8Rank: 8

沙发
发表于 2014-4-23 11:40:09 |只看该作者
本帖最后由 felt 于 2014-4-23 11:41 编辑

列4列5你既然是自动填充的,为什么还要修改
修改完还是会触发drawcell绘制的

Rank: 1

板凳
发表于 2014-4-23 12:11:38 |只看该作者
felt 发表于 2014-4-23 11:40
列4列5你既然是自动填充的,为什么还要修改
修改完还是会触发drawcell绘制的
...

可能会差个零点零几 或者 零点几的 就需要调整一下

  那么怎么解决这个问题呢?

Rank: 1

地板
发表于 2014-4-23 12:13:45 |只看该作者
felt 发表于 2014-4-23 11:40
列4列5你既然是自动填充的,为什么还要修改
修改完还是会触发drawcell绘制的
...

而且在里面没有用到drawcell事件呀

Rank: 8Rank: 8

5#
发表于 2014-4-23 13:12:49 |只看该作者
yangfei_wow 发表于 2014-4-23 12:13
而且在里面没有用到drawcell事件呀

那你列4,列5怎么计算的

Rank: 1

6#
发表于 2014-4-23 13:23:24 |只看该作者
felt 发表于 2014-4-23 13:12
那你列4,列5怎么计算的

在CellBeginEdit事件里
if(field==='列4'){
e.editor.setValue(列1/列2);   //假设是这种简单的算法
row.列5=列1*列2;
}

Rank: 8Rank: 8

7#
发表于 2014-4-23 15:29:14 |只看该作者
yangfei_wow 发表于 2014-4-23 13:23
在CellBeginEdit事件里
if(field==='列4'){
e.editor.setValue(列1/列2);   //假设是这种简单的算法

你做个重现的简单html页面上来,我们看下

Rank: 1

8#
发表于 2014-4-23 16:15:53 |只看该作者
  1. <body>
  2.     <div>
  3.         <div id="datagrid1" class="mini-datagrid" style="width: 100%; height: 500px;" editnextonenterkey="true" autoselect="true" idfield="ID" allowcelledit="true" allowcellvalid="true" showpager="false" oncellendedit="onCellEndEdit" allowcellselect="true" oncellbeginedit="onCellBeginEdit">
  4.             <div property="columns">
  5.                   <div name="Name" field="Name" width="35%" vtype="required" headeralign="center" align="center" align="center">
  6.                     产品
  7.                         <input property="editor" class="mini-textbox" onbuttonclick="" style="width: 100%;" />
  8.                 </div>
  9.                 <div name="Qty" field="Qty" width="35%" vtype="required" headeralign="center" align="center" align="center" summarytype="sum">
  10.                     数量*
  11.                         <input property="editor" class="mini-textbox" onbuttonclick="" style="width: 100%;" />
  12.                 </div>
  13.                 <div name="TaxPrice" field="TaxPrice" width="35%" vtype="required" headeralign="center" align="right">
  14.                     含税单价*   
  15.                     <input property="editor" class="mini-textbox" onbuttonclick="" style="width: 100%;" />
  16.                 </div>
  17.                 <div name="Price" field="Price" width="35%" vtype="required" align="right" headeralign="center">
  18.                     不含税单价
  19.                          <input property="editor" class="mini-textbox" onbuttonclick="" style="width: 100%;" />
  20.                 </div>
  21.                 <div name="DiscountRate" field="DiscountRate" width="35%" vtype="required" headeralign="center" align="center">
  22.                     折扣率(%)*   
  23.                     <input property="editor" class="mini-textbox" onbuttonclick="" style="width: 100%;" />
  24.                 </div>

  25.                 <div name="RealTaxPrice" field="RealTaxPrice" width="35%" vtype="required" headeralign="center" align="right">
  26.                     实际含税单价
  27.                          <input property="editor" class="mini-textbox" onbuttonclick="" style="width: 100%;" />
  28.                 </div>
  29.                 <div name="RealPrice" field="RealPrice" width="35%" vtype="required" align="right" headeralign="center">
  30.                     实际不含税单价
  31.                          <input property="editor" class="mini-textbox" onbuttonclick="" style="width: 100%;" />
  32.                 </div>

  33.                 <div name="Amount" field="Amount" width="35%" vtype="required" headeralign="center" align="right" summarytype="sum">
  34.                     不含税金额   
  35.                     <input property="editor" class="mini-textbox" onbuttonclick="" style="width: 100%;" />
  36.                 </div>
  37.                 <div name="Deduction" field="Deduction" width="35%" vtype="required" headeralign="center" align="right" summarytype="sum">
  38.                     折扣额
  39.                           <input property="editor" class="mini-textbox" onbuttonclick="" style="width: 100%;" />
  40.                 </div>
  41.                 <div name="TaxRate" field="TaxRate" width="25%" vtype="required" headeralign="center" align="center">
  42.                     税率(%)*   
  43.                     <input property="editor" class="mini-textbox" onbuttonclick="" style="width: 100%;" />
  44.                 </div>
  45.                 <div name="Tax" field="Tax" width="35%" vtype="required" headeralign="center" align="center">
  46.                     税额
  47.                      <input property="editor" class="mini-textbox" onbuttonclick="" style="width: 100%;" />
  48.                 </div>
  49.                 <div name="TaxAmount" field="TaxAmount" width="35%" vtype="required" headeralign="center" align="center">
  50.                     价税合计
  51.                      <input property="editor" class="mini-textbox" onbuttonclick="" style="width: 100%;" onenter="EnterAdd" />
  52.                 </div>
  53.             </div>
  54.         </div>
  55.     </div>
  56. </body>
复制代码

Rank: 1

9#
发表于 2014-4-23 16:16:33 |只看该作者
  1. <script type="text/javascript">
  2.     mini.parse();
  3.     var grid = mini.get("datagrid1");
  4.     function addGridRow() {
  5.         var newRow = {Name: "",  Qty: "", TaxPrice: "", Price: "", DiscountRate: "", RealTaxPrice: "", RealPrice: "", Amount: "", Deduction: "", TaxRate: 17, Tax: "", TaxAmount: "", Amount: "", Description: "", gCode: "" };
  6.         grid.addRow(newRow);
  7.     }
  8.     $(document).ready(function () {
  9.         for (var i = 0; i < 5; i++) {
  10.             addGridRow();
  11.         }
  12.     });
  13.     function onCellBeginEdit(e) {
  14.         var row = grid.getSelected();
  15.         //不含税单价
  16.         if (e.field === "Price") {
  17.             $.ajax({
  18.                 url: "?",
  19.                 success: function (data) {
  20.                     var taxPrice = row["TaxPrice"];
  21.                     var taxRate = row["TaxRate"];
  22.                     if (taxPrice === "")
  23.                         taxPrice = 0;
  24.                     if (taxRate === "")
  25.                         taxRate = 0;
  26.                     var price = taxPrice / (1 + taxRate / 100);
  27.                     e.editor.setValue(price.toFixed(4));
  28.                 }
  29.             })
  30.             //row.Price = (row["TaxPrice"] / (1 + row["TaxRate"] / 100)).toFixed(4);
  31.             //grid.getCellEditor(grid.getColumn("Price"), row).setValue(row.Price);
  32.             if (row["DiscountRate"] === "")
  33.                 row["DiscountRate"] = 0;
  34.             row.RealTaxPrice = (row["TaxPrice"] * (1 - row["DiscountRate"] / 100)).toFixed(4);
  35.             if (row["TaxRate"] === "")
  36.                 row["TaxRate"] = 0;
  37.             row.RealPrice = (row["RealTaxPrice"] / (1 + row["TaxRate"] / 100)).toFixed(4);
  38.             row.Amount = (row["RealPrice"] * row["Qty"]).toFixed(2);
  39.             row.Deduction = (row["TaxPrice"] * row["Qty"] * (row["DiscountRate"] / 100)).toFixed(2);
  40.             row.TaxAmount = (row["Qty"] * row["RealTaxPrice"]).toFixed(2);
  41.             if (row["TaxRate"] === "")
  42.                 row["TaxRate"] = 0;
  43.             row.Tax = (row["TaxAmount"] - row["Amount"]).toFixed(2);
  44.         }
  45.         //实际含税单价
  46.         if (e.field === "RealTaxPrice") {
  47.             $.ajax({
  48.                 url: "?",
  49.                 success: function (data) {
  50.                     row.Price = (row["TaxPrice"] / (1 + row["TaxRate"] / 100)).toFixed(4);
  51.                     var taxPrice = row["TaxPrice"];
  52.                     var discountRate = row["DiscountRate"];
  53.                     if (taxPrice === "")
  54.                         taxPrice = 0;
  55.                     if (discountRate === "")
  56.                         discountRate = 0;
  57.                     var price = taxPrice * (1 - discountRate / 100);
  58.                     e.editor.setValue(price.toFixed(4));
  59.                     row.RealTaxPrice = price.toFixed(4);
  60.                     if (row["TaxRate"] === "")
  61.                         row["TaxRate"] = 0;
  62.                     row.RealPrice = (row["RealTaxPrice"] / (1 + row["TaxRate"] / 100)).toFixed(4);
  63.                     row.Amount = (row["RealPrice"] * row["Qty"]).toFixed(2);
  64.                     row.Deduction = (row["TaxPrice"] * row["Qty"] * (row["DiscountRate"] / 100)).toFixed(2);
  65.                     row.TaxAmount = (row["Qty"] * row["RealTaxPrice"]).toFixed(2);
  66.                     if (row["TaxRate"] === "")
  67.                         row["TaxRate"] = 0;
  68.                     row.Tax = (row["TaxAmount"] - row["Amount"]).toFixed(2);
  69.                 }
  70.             })
  71.         }
  72.         //折扣额
  73.         if (e.field === "Deduction") {
  74.             $.ajax({
  75.                 async: false,
  76.                 url: "?",
  77.                 success: function (data) {
  78.                     var taxPrice = row["TaxPrice"];
  79.                     var dRate = row["DiscountRate"];
  80.                     var qty = row["Qty"];
  81.                     if (taxPrice === "")
  82.                         taxPrice = 0;
  83.                     if (dRate === "")
  84.                         dRate = 0;
  85.                     if (qty === "")
  86.                         qty = 0;
  87.                     var price = taxPrice * qty * (dRate / 100);
  88.                     e.editor.setValue("");
  89.                     e.editor.setValue(price.toFixed(2));
  90.                     row.Deduction = price.toFixed(2);
  91.                 }
  92.             })   
  93.         }
  94.         //税额
  95.         if (e.field === "Tax") {
  96.             //Price
  97.             row.Price = (row["TaxPrice"] / (1 + row["TaxRate"] / 100)).toFixed(4);
  98.             if (row["DiscountRate"] === "")
  99.                 row["DiscountRate"] = 0;
  100.             row.RealTaxPrice = (row["TaxPrice"] * (1 - row["DiscountRate"] / 100)).toFixed(4);
  101.             if (row["TaxRate"] === "")
  102.                 row["TaxRate"] = 0;
  103.             row.RealPrice = (row["RealTaxPrice"] / (1 + row["TaxRate"] / 100)).toFixed(4);
  104.             row.Amount = (row["RealPrice"] * row["Qty"]).toFixed(2);
  105.             row.Deduction = ((row["TaxPrice"] - row["RealTaxPrice"]) * row["Qty"]).toFixed(2);
  106.             if (row["TaxRate"] === "")
  107.                 row["TaxRate"] = 0;
  108.             row.TaxAmount = (row["Qty"] * row["RealTaxPrice"]).toFixed(2);
  109.             $.ajax({
  110.                 url: "?",
  111.                 success: function (data) {
  112.                     var amount = row["Amount"];
  113.                     var taxAmount = row["TaxAmount"];
  114.                     if (amount === "")
  115.                         amount = 0;
  116.                     if (taxAmount === "")
  117.                         taxAmount = 0;
  118.                     var price = taxAmount - amount;
  119.                     e.editor.setValue(price.toFixed(2));
  120.                 }
  121.             })
  122.         }
  123.         //价税合计
  124.         if (e.field === "TaxAmount") {
  125.             $.ajax({
  126.                 url: "?",
  127.                 success: function (data) {
  128.                     var qty = row["Qty"];
  129.                     var rtp = row["RealTaxPrice"];
  130.                     if (qty === "")
  131.                         qty = 0;
  132.                     if (rtp === "")
  133.                         rtp = 0;
  134.                     var taxAmount = (rtp * qty).toFixed(2);
  135.                     e.editor.setValue(taxAmount);
  136.                 }
  137.             })
  138.         }
  139.     }
  140.     function onCellEndEdit(e) {
  141.         var row = grid.getSelected();
  142.         if (e.field === "TaxRate") {
  143.             if (e.value !== 17) {

  144.             }
  145.         }
  146.     }
  147.     function EnterAdd(e) {
  148.         if (e.source.ownerRowID == grid.getData().length - 1) {
  149.             addGridRow();
  150.         }
  151.     }
  152. </script>
复制代码

Rank: 1

10#
发表于 2014-4-23 16:17:26 |只看该作者
felt 发表于 2014-4-23 15:29
你做个重现的简单html页面上来,我们看下

发到楼下了  您看下    字数原因    分成两个贴了   

Archiver|普加软件

GMT+8, 2024-9-29 07:22 , Processed in 1.025803 second(s), 11 queries .

Powered by Discuz! X2

© 2001-2011 Comsenz Inc.

回顶部