easyUI在可编辑的datagrid中加入combogrid 实现下拉选择填充列
来源:互联网 发布:windows phone 8.1 编辑:程序博客网 时间:2024/06/10 08:35
在公司的项目中,有需要再添加数据的时候,通过下来选择数据来完成数据的填充。
网上找了很多关于datagrid绑定 combogrid的方法,都不能很好的解决问题,于是自己根据easyUI的api完成了这个方法。
ID为OtherFees的table 是一个datagrid;
在绑定的字段中,字段fee_name可以编辑的editor,类型为combogrid。所以在红色部分实现了对这个editor的绑定。
在combogrid中,要实现选择费用名称后,对其他字段(如:费用金额fee_price,折扣discount,实际金额real_amount)的绑定填充。就需要在combogrid的onSelect方法中完成editor的赋值(setvalue)。
所以蓝色部分就是onSelect选中的具体方法。
首选通过:var rowIndex= grid.datagrid('getRowIndex',grid.datagrid('getSelected')); 获取到当前datagrid的当前编辑列的索引ID。
用到了datagrid中editor的两个方法。
============华丽丽的代码分割线=================
<table id="OtherFees" style="width:auto;height:auto"title="Editable DataGrid" iconCls="icon-edit" singleSelect="true"idField="itemid" ><thead><tr> <th field="sheet_no" hidden="true"></th> <th field="flow_no" hidden="true"></th> <th field="itemid" align="left" width="40" >ID </th> <th field="cost_amount" editor="{type: 'text'}" ></th> <th field="fee_name" align="left" width="160" editor="{type: 'combogrid', options: { url: '获取费用的URL', panelWidth:200, idField: 'feename', textField: 'feename', columns:[[{field:'feename',title:'费用名称',width:140},{field:'saleprice',title:'费用金额',width:60},{field:'costprice',title:'费用金额',width:60}]], onSelect: function (index, row) { </span><span style="color:#3366ff;"> var grid = $('#OtherFees');</span><span style="color:#33ccff;"> </span><span style="color:#3366ff;">var rowIndex= grid.datagrid('getRowIndex',grid.datagrid('getSelected')); grid.datagrid('beginEdit', rowIndex); var editors = grid.datagrid('getEditors', rowIndex); var fee_price, discount, real_amount; fee_price = grid.datagrid('getEditor', { index: rowIndex, field: 'fee_price' }); discount = grid.datagrid('getEditor', { index: rowIndex, field: 'discount' }); real_amount = grid.datagrid('getEditor', { index: rowIndex, field: 'real_amount' }); $(fee_price.target).numberbox('setValue',row.saleprice); $(real_amount.target).numberbox('setValue',row.saleprice); $(fee_price.target).bind('change', function () { $(real_amount.target).numberbox('setValue', $(fee_price.target).val() * $(discount.target).val()); }); $(discount.target).bind('change', function () { $(real_amount.target).numberbox('setValue', $(fee_price.target).val() * $(discount.target).val()); }); } }}">费用名称 </th></span> <th field="fee_price" align="left" width="60" editor="{type: 'numberbox', options: {required: true, precision: 1}}">费用金额 </th> <th field="discount" align="left" width="60" editor="{type: 'numberbox', options: {required: true, precision: 1}}">折扣 </th> <th field="real_amount" align="left" width="60" editor="{type: 'numberbox', options: {required: true, precision: 1}}" >实收 </th> <th field="repair_property" align="center" width="120" editor="{type: 'combobox', options: {required: true, precision: 1, url: '../../Ajax/Ajax_Common.ashx?action=getRepairPropertyInfo&branch_no=<%=GetAdminBranch.branch_no%>', valueField: 'propertyname', textField: 'propertyname' }}" >维修性质</th> <th field="memo" align="left" width="200 "editor="{type: 'text'}" >备注 </th></tr> </thead></table>
===============另外说一下=================
如果是通过JavaScript来初始化datagrid列的朋友,你可以把combogrid的绑定,以及对combogrid中的onselect中的代码重新进行分开调用。
在onselect中引入下面的方法:
function SetFeesValue(){ var grid = $('#OtherFees'); var rowIndex= grid.datagrid('getRowIndex',grid.datagrid('getSelected')); grid.datagrid('beginEdit', rowIndex); var editors = grid.datagrid('getEditors', rowIndex); var fee_price, discount, real_amount; fee_price = grid.datagrid('getEditor', { index: rowIndex, field: 'fee_price' }); discount = grid.datagrid('getEditor', { index: rowIndex, field: 'discount' }); real_amount = grid.datagrid('getEditor', { index: rowIndex, field: 'real_amount' }); $(fee_price.target).numberbox('setValue',row.saleprice); $(real_amount.target).numberbox('setValue',row.saleprice);/赋值 $(fee_price.target).bind('change', function () { $(real_amount.target).numberbox('setValue', $(fee_price.target).val() * $(discount.target).val()); }); $(discount.target).bind('change', function () { $(real_amount.target).numberbox('setValue', $(fee_price.target).val() * $(discount.target).val()); });}
0 0
- easyUI在可编辑的datagrid中加入combogrid 实现下拉选择填充列
- easyUI在可编辑的datagrid中加入combogrid 实现下拉选择填充列
- easyui DataGrid editors扩展之combogrid ,combogrid 下拉选择后填充 editor 列内容方法
- easyui datagrid 编辑行绑定combogrid并实现下拉赋值
- easyUI在可编辑的datagrid中计算两列的值
- easyUI在可编辑的datagrid中计算两列的值
- 【easyui】datagrid的列可编辑
- EasyUI-DataGrid编辑时出现下拉列表框选择,同时修改其它列的值
- easyui实现可新增不可编辑的datagrid及动态配置列隐藏/显示
- 【easyUI】下拉框中加datagrid-combogrid组件应用
- 如何取消选择easyui-combogrid的下拉数据
- jQuery-easyUI的使用:datagrid实现可编辑表格
- easyui的datagrid中editor和combogrid的结合使用
- easyui-datagrid行编辑每增加一行,某列的单元格自动填充指定内容
- JQUERY EASYUI DATAGRID设置可编辑行的某个列不可编辑
- EasyUI datagrid可编辑
- Easyui - datagrid 列编辑
- jquery easyui 中combogrid , datagrid 自定义分页
- iOS之小技巧总结,绝对有你想要的
- 程序设计与算法 第七周测验
- iOS10的适配(一)
- JVM内存区域详解(Eden Space、Survivor Space、Old Gen、Code Cache和Perm Gen)
- 调度策略
- easyUI在可编辑的datagrid中加入combogrid 实现下拉选择填充列
- join方法的理解
- Javascript定义类(class)的三种方法
- 4.通信层
- APP漏洞自动化扫描专业评测报告(下篇)
- 数字转字母顺序 JS实现
- nginx安装配置
- Python核心模块方法
- 大数据系列修炼-Scala课程35