课程表

jEasyUI 应用

jEasyUI 拖放

jEasyUI 菜单与按钮

jEasyUI 布局

jEasyUI 数据网格

jEasyUI 窗口

jEasyUI 树形菜单

jEasyUI 表单

jEasyUI 参考手册

工具箱
速查手册

jEasyUI 列运算

当前位置:免费教程 » JS/JS库/框架 » jQuery EasyUI

在本教程中,您将学习如何在可编辑的数据网格(datagrid)中包含一个运算的列。一个运算列通常包含一些从一个或多个其他列运算的值。

首先,创建一个可编辑的数据网格(datagrid)。这里我们创建了一些可编辑列,'listprice'、'amount' 和 'unitcost' 列定义为 numberbox 编辑类型。运算列是 'unitcost' 字段,将是 listprice 乘以 amount 列的结果。

  1. <table id="tt" style="width:600px;height:auto"
  2. title="Editable DataGrid with Calculated Column" iconCls="icon-edit" singleSelect="true"
  3. idField="itemid" url="data/datagrid_data.json">
  4. <thead>
  5. <tr>
  6. <th field="itemid" width="80">Item ID</th>
  7. <th field="listprice" width="80" align="right" editor="{type:'numberbox',options:{precision:1}}">List Price</th>
  8. <th field="amount" width="80" align="right" editor="{type:'numberbox',options:{precision:0}}">Amount</th>
  9. <th field="unitcost" width="80" align="right" editor="numberbox">Unit Cost</th>
  10. <th field="attr1" width="150" editor="text">Attribute</th>
  11. <th field="status" width="60" align="center" editor="{type:'checkbox',options:{on:'P',off:''}}">Status</th>
  12. </tr>
  13. </thead>
  14. </table>

当用户点击一行的时候,我们开始一个编辑动作。

  1. var lastIndex;
  2. $('#tt').datagrid({
  3. onClickRow:function(rowIndex){
  4. if (lastIndex != rowIndex){
  5. $('#tt').datagrid('endEdit', lastIndex);
  6. $('#tt').datagrid('beginEdit', rowIndex);
  7. setEditing(rowIndex);
  8. }
  9. lastIndex = rowIndex;
  10. }
  11. });

为了在一些列之间创建运算关系,我们应该得到当前的 editors,并绑定一些事件到它们上面。

  1. function setEditing(rowIndex){
  2. var editors = $('#tt').datagrid('getEditors', rowIndex);
  3. var priceEditor = editors[0];
  4. var amountEditor = editors[1];
  5. var costEditor = editors[2];
  6. priceEditor.target.bind('change', function(){
  7. calculate();
  8. });
  9. amountEditor.target.bind('change', function(){
  10. calculate();
  11. });
  12. function calculate(){
  13. var cost = priceEditor.target.val() * amountEditor.target.val();
  14. $(costEditor.target).numberbox('setValue',cost);
  15. }
  16. }

下载 jQuery EasyUI 实例

jeasyui-datagrid-datagrid15.zip

转载本站内容时,请务必注明来自W3xue,违者必究。
 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号