easyUI在可编辑的datagrid中计算两列的值
2015-12-15 09:51
459 查看
在本教程中,您将学习如何在可编辑的数据网格(datagrid)中包含一个运算的列。一个运算列通常包含一些从一个或多个其他列运算的值。
![](http://www.qeefee.com/upload/spider/S167/1.png)
首先,创建一个可编辑的数据网格(datagrid)。这里我们创建了一些可编辑列,'listprice'、'amount' 和 'unitcost' 列定义为 numberbox 编辑类型。运算列是 'unitcost' 字段,将是 listprice 乘以 amount 列的结果。
当用户点击一行的时候,我们开始一个编辑动作。
为了在一些列之间创建运算关系,我们应该得到当前的 editors,并绑定一些事件到它们上面。
![](http://www.qeefee.com/upload/spider/S167/1.png)
首先,创建一个可编辑的数据网格(datagrid)。这里我们创建了一些可编辑列,'listprice'、'amount' 和 'unitcost' 列定义为 numberbox 编辑类型。运算列是 'unitcost' 字段,将是 listprice 乘以 amount 列的结果。
<table id="tt" style="width:600px;height:auto" title="Editable DataGrid with Calculated Column" iconCls="icon-edit" singleSelect="true" idField="itemid" url="data/datagrid_data.json"> <thead> <tr> <th field="itemid" width="80">Item ID</th> <th field="listprice" width="80" align="right" editor="{type:'numberbox',options:{precision:1}}">List Price</th> <th field="amount" width="80" align="right" editor="{type:'numberbox',options:{precision:0}}">Amount</th> <th field="unitcost" width="80" align="right" editor="numberbox">Unit Cost</th> <th field="attr1" width="150" editor="text">Attribute</th> <th field="status" width="60" align="center" editor="{type:'checkbox',options:{on:'P',off:''}}">Status</th> </tr> </thead> </table>
当用户点击一行的时候,我们开始一个编辑动作。
var lastIndex; $('#tt').datagrid({ onClickRow:function(rowIndex){ if (lastIndex != rowIndex){ $('#tt').datagrid('endEdit', lastIndex); $('#tt').datagrid('beginEdit', rowIndex); setEditing(rowIndex); } lastIndex = rowIndex; } });
为了在一些列之间创建运算关系,我们应该得到当前的 editors,并绑定一些事件到它们上面。
function setEditing(rowIndex){ var editors = $('#tt').datagrid('getEditors', rowIndex); var priceEditor = editors[0]; var amountEditor = editors[1]; var costEditor = editors[2]; priceEditor.target.bind('change', function(){ calculate(); }); amountEditor.target.bind('change', function(){ calculate(); }); function calculate(){ var cost = priceEditor.target.val() * amountEditor.target.val(); $(costEditor.target).numberbox('setValue',cost); } }
相关文章推荐
- Java GUI入门教程
- 应用Druid监控SQL语句的执行情况
- UIViewContentMode各类型效果
- Querying JSON
- ORA-12520: TNS:listener could not find available handler for requested type of server
- 详解iOS开发中UItableview控件的数据刷新功能的实现
- Arduino - 改装车库门,增设手机蓝牙控制功能
- ios UITableview 刷新某一个cell 或 section
- 《UIPageControl 的创建和 自定义和引导页的使用》
- iOS9 新增 UIStackView 官方文档翻译
- iOS UIScrollView 没有从顶部开始滑动
- Arduino - Micro SD卡 读写
- 298. Binary Tree Longest Consecutive Sequence
- iOS之UI--使用SWRevealViewController实现侧边菜单功能详解实例
- setProjectionMap@SQLiteQueryBuilder使用简记
- Android Service更新UI的方法之AIDL
- HDU 1242 Rescue
- UILabel的富文本设置
- UICollection 找不同--小游戏
- push to bluemix and get wrong