EasyUI----DataGrid行明细增删改操作
- $(function(){
- $("#listDetail").datagrid({
- heigth:700,
- idField:'id',
- url:'<oz:contextPath/>/oa/receiptNoteDetailAction.do?action=page',
- queryParams:{'viewType':'RK','RKD_ID':_rkdId},
- singleSelect:false,
- fitColumns:true,
- nowrap:true,
- columns:[[
- {field:'id',checkbox:true},
- {field:'name',title:'用品名称',width:100,editor:'text',sortable:true},
- {field:'produceType',title:'用品型号',width:100,editor:'text',sortable:true},
- {field:'prickle',title:'计量单位',width:100,editor:'text',sortable:true},
- {field:'count',title:'入库数量',width:100,editor:'text',sortable:true},
- {field:'price',title:'参考单价',width:100,editor:'text',sortable:true},
- {field:'subtotal',title:'入库金额',width:100,editor:'text',sortable:true}
- ]],
- toolbar:[{
- text:'添加',
- <span style="white-space:pre"> <span style="white-space:pre"> </span></span>iconCls:'icon-add',
- <span style="white-space:pre"> <span style="white-space:pre"> </span></span>handler:addItem
- },{
- text:'删除',
- <span style="white-space:pre"> </span>iconCls:'icon-remove',
- <span style="white-space:pre"> </span>handler:deleteItem
- },{
- text:'刷新',
- <span style="white-space:pre"> </span>iconCls:'icon-reload',
- <span style="white-space:pre"> </span>handler:refresh
- }],
- view: detailview,
- detailFormatter:function(index,row){
- return '<div id="detailForm-'+index+'" style="line-height:500px;"></div>';
- },
- onExpandRow: function(index,row){
- var id= $(this).datagrid('getRows')[index].id;
- $('#detailForm-'+index).panel({
- doSize:true,
- border:false,
- cache:false,
- href:'<oz:contextPath/>/oa/suppliesmgm/DE_ReceiptNoteDetail.jsp?rkdId='+_rkdId+'&id='+id+'&index='+index,
- onLoad:function(){
- $('#listDetail').datagrid('fixDetailRowHeight',index);
- $('#listDetail').datagrid('selectRow',index);
- }
- });
- $('#listDetail').datagrid('fixDetailRowHeight',index);
- },
- onDblClickRow:function(index,row){
- $('#listDetail').datagrid('expandRow', index);
- $('#listDetail').datagrid('fitColumns',index);
- $('#listDetail').datagrid('selectRow', index);
- }
- });
- });
特殊参数说明:
- //添加
- function addItem(){
- $('#listDetail').datagrid('appendRow',{isNewRecord:true});
- var index = $('#listDetail').datagrid('getRows').length - 1;
- $('#listDetail').datagrid('expandRow', index);
- $('#listDetail').datagrid('fitColumns',index);
- $('#listDetail').datagrid('selectRow', index);
- }
- //删除
- function deleteItem(){
- var rows = $('#listDetail').datagrid('getSelections');
- if (null == rows || rows.length == 0) {
- OZ.Msg.info('请选择用品');
- return;
- }
- var ids=[];
- for(var i=0;i<rows.length;i++){
- ids.push(rows[i].id);
- }
- OZ.Msg.confirm(
- '删除入库用品明细将直接影响库存信息,确定删除吗?',
- function(){
- $.getJSON(
- contextPath + "/oa/receiptNoteDetailAction.do?action=deleteDetail&timeStamp=" + new Date().getTime(),
- {ids:ids.join(";")},
- function(json){
- if(json.result == true){
- OZ.Msg.info('删除成功');
- $('#listDetail').datagrid('reload');
- parent.refresh();//刷新上级页面
- }else{
- OZ.Msg.info('抱歉,删除失败');
- }
- }
- );
- }
- );
- }
- //保存
- function saveItem(index){
- var suppliesCount=$('#detailForm-'+index).find("#suppliesCount").val(),
- count=$('#detailForm-'+index).find("#count").val();
- if(count == '' && count.length<1){
- OZ.Msg.info("出库数量不能为空");
- return false;
- }
- if(parseInt(count) > parseInt(suppliesCount)){
- OZ.Msg.info("出库数量不能大于实际库存数量");
- return false;
- }
- var strUrl = contextPath+'/oa/issueNoteDetailAction.do?action=saveByAjax&timeStamp=' + (new Date().getTime());
- $.ajax({
- type: "POST",
- dataType: "json",
- url:strUrl ,
- data: $('#ozForm').serialize(),
- success: function(json, _status){
- $('#listDetail').datagrid('collapseRow',index);
- $('#listDetail').datagrid('reload');
- parent.refresh();//刷新上级页面
- },
- error: function(xhr, errorMsg, errorThrown){
- OZ.Msg.error("保存操作出现未处理异常!");
- }
- });
- }
- //取消
- function cancelItem(index){
- var row = $('#listDetail').datagrid('getRows')[index];
- if (row.isNewRecord){
- $('#listDetail').datagrid('deleteRow',index);
- } else {
- $('#listDetail').datagrid('collapseRow',index);
- }
- }
- <html:form action="oa/issueNoteDetailAction.do" styleId="ozForm" styleClass="oz-form">
- <div class="oz-form-fields">
- <table cellpadding="0" cellspacing="0" class="dv-table" style="width:600px;background:#fafafa;padding:5px;margin-top:5px;">
- <tr>
- <td colspan="4">
- <div>
- <a href="#" class="easyui-linkbutton" iconCls="icon-save" plain="true" onclick="saveItem(<%= request.getParameter("index") %>)" id="btnSave">保存</a>
- <a href="#" class="easyui-linkbutton" iconCls="icon-cancel" plain="true" onclick="cancelItem(<%= request.getParameter("index") %>)">取消</a>
- </div>
- <hr/>
- </td>
- </tr>
- <tr>
- <td class="oz-form-label" style="width:80px">库存用品:</td>
- <td class="oz-property" colspan="3">
- <html:text property="supplies.name" styleId="suppliesName" styleClass="oz-form-zdField" readonly="true" style="width:150px"/>
- <button type="button" class="oz-form-button" onClick="onBtnSelectSupplies_Clicked(<%= request.getParameter("index") %>);">选择..</button>
- </td>
- </tr>
- <tr>
- <td class="oz-form-label" style="width:80px">用品型号:</td>
- <td class="oz-property">
- <html:text property="supplies.productType" styleId="suppliesProductType" styleClass="oz-form-zdField" readonly="true" style="width:150px"/>
- </td>
- <td class="oz-form-label" style="width:80px">参考单价:</td>
- <td class="oz-property">
- <html:text property="supplies.price" styleId="suppliesPrice" styleClass="oz-form-zdField" readonly="true" style="width:150px"/>
- </td>
- </tr>
- <tr>
- <td class="oz-form-label" style="width:80px">计量单位:</td>
- <td class="oz-property">
- <html:text property="supplies.prickle" styleId="suppliesPrickle" styleClass="oz-form-zdField" readonly="true" style="width:150px"/>
- </td>
- <td class="oz-form-label" style="width:100px">实际库存数量:</td>
- <td class="oz-property">
- <html:text property="supplies.realCount" styleId="suppliesRealCount" styleClass="oz-form-zdField" readonly="true" style="width:150px"/>
- </td>
- </tr>
- <tr>
- <td class="oz-form-label" style="width:80px">出库数量:</td>
- <td class="oz-property" colspan="3">
- <html:text property="count" styleId="count" styleClass="oz-form-btField" style="width:150px"/>
- </td>
- </tr>
- <tr>
- <td class="oz-form-label" style="width:80px">备注:</td>
- <td class="oz-property" colspan="3">
- <html:textarea property="beizhu" styleId="beizhu" styleClass="oz-form-field" style="width:500px" cols="15"/>
- </td>
- </tr>
- </table>
- </div>
- <html:hidden property="id" styleId="id"/>
- <html:hidden property="supplies.id" styleId="suppliesId"/>
- <html:hidden property="issueNote.id" styleId="issueNoteId"/>
- </html:form>
因为在初始化的时候有传id,rkdid,index参数过来,意义在于加载此Form的时候,可以利用Json根据id重新加载数据,这样可以避免保存外键时候出错。
- var id=<%= request.getParameter("id") %>;
- var _ckdId=<%= request.getParameter("ckdId") %>;
- var _index = <%= request.getParameter("index") %>;
- $(function(){
- $('#detailForm-'+_index).find('#issueNoteId').val(_ckdId);
- loadomain();
- validate();
- });
- function loadomain(){
- if(typeof id == "undefined")
- id=-1;
- $.getJSON(
- contextPath + '/oa/issueNoteDetailAction.do?action=getIssueNoteDetail&id=' + id + '&timeStamp=' + new Date().getTime(),
- function(json){
- if(!json.isNew){
- $('#detailForm-'+_index).find('#id').val(json.id);
- $('#detailForm-'+_index).find('#beizhu').val(json.beizhu);
- $('#detailForm-'+_index).find('#count').val(json.count);
- $('#detailForm-'+_index).find('#suppliesId').val(json.suppliesId);
- $('#detailForm-'+_index).find('#suppliesPrickle').val(json.suppilesPrickle);
- $('#detailForm-'+_index).find('#suppliesProductType').val(json.suppliesProductType);
- $('#detailForm-'+_index).find('#suppliesPrice').val(json.suppliesPrice);
- $('#detailForm-'+_index).find('#suppliesName').val(json.suppliesName);
- $('#detailForm-'+_index).find('#suppliesRealCount').val(json.suppliesRealCount);
- }else{
- $('#detailForm-'+_index).find('#id').val(id);
- }
- })
- }
同时,重新加载数据时候注意按照不同DIV找到不同Form的各个字段,否则会加载数据错位。
- public ActionForward getIssueNoteDetail(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws Exception{
- Long id=RequestUtils.getLongParameter(request, "id", -1);
- JSONObject json=new JSONObject();
- json.put("isNew",Boolean.valueOf(false));
- if(id != -1){
- IssueNoteDetail detail=this.getService().load(id);
- json.put("suppliesId",detail.getSupplies().getId());
- json.put("suppliesName",detail.getSupplies().getName());
- json.put("suppliesPrice",detail.getSupplies().getPrice());
- json.put("suppliesProductType",detail.getSupplies().getProductType());
- json.put("suppilesPrickle",detail.getSupplies().getPrickle());
- json.put("suppliesCount",detail.getSupplies().getCount());
- json.put("suppliesRealCount",detail.getSupplies().getRealCount());
- json.put("id",id);
- json.put("beizhu",detail.getBeizhu());
- json.put("count",detail.getCount());
- }else{
- json.put("isNew",Boolean.valueOf(true));
- }
- return renderJson(response, json.toString());
- }
EasyUI----DataGrid行明细增删改操作的更多相关文章
- easyui学习笔记1—增删改操作
最近公司要用easyui,这里自己看了官网几篇文章,遇到些问题,大多数的问题都是敲代码的时候笔误,其他有些地方确实需要注意一下,这里做些笔记. 1.在mysql中建好表之后修改id字段为递增字段,发现 ...
- Jquery easyui开启行编辑模式增删改操作
Jquery easyui开启行编辑模式增删改操作 Jquery easyui开启行编辑模式增删改操作先上图 Html代码: <table id="dd"> </ ...
- [转]Jquery easyui开启行编辑模式增删改操作
本文转自:http://www.cnblogs.com/nyzhai/archive/2013/05/14/3077152.html Jquery easyui开启行编辑模式增删改操作先上图 Html ...
- SSM框架搭建(Spring+SpringMVC+MyBatis)与easyui集成并实现增删改查实现
一.用myEclipse初始化Web项目 新建一个web project: 二.创建包 controller //控制类 service //服务接口 service.impl //服务 ...
- OracleHelper(对增删改查分页查询操作进行了面向对象的封装,对批量增删改操作的事务封装)
公司的一个新项目使用ASP.NET MVC开发,经理让我写个OracleHelper,我从网上找了一个比较全的OracleHelper类,缺点是查询的时候返回DataSet,数据增删改要写很多代码(当 ...
- Linq to SQL 简单的增删改操作
Linq to SQL 简单的增删改操作. 新建数据库表tbGuestBook.结构如下: 新建web项目,完成相应的dbml文件.留言页面布局如下 <body> <form id= ...
- 【2017-05-02】winform弹出警告框是否进行增删改操作、记事本制作、对话框控件和输出输入流
一.winform弹出警告框是否进行增删改操作 第一个参数是弹出窗体显示的内容,第二个参数是标题,第三个参数是该弹窗包含确定和取消按钮. 返回的是一个枚举类接收一下. 再进行判断,如果点的是确定按钮, ...
- ASP.NET MVC深入浅出(被替换) 第一节: 结合EF的本地缓存属性来介绍【EF增删改操作】的几种形式 第三节: EF调用普通SQL语句的两类封装(ExecuteSqlCommand和SqlQuery ) 第四节: EF调用存储过程的通用写法和DBFirst模式子类调用的特有写法 第六节: EF高级属性(二) 之延迟加载、立即加载、显示加载(含导航属性) 第十节: EF的三种追踪
ASP.NET MVC深入浅出(被替换) 一. 谈情怀-ASP.NET体系 从事.Net开发以来,最先接触的Web开发框架是Asp.Net WebForm,该框架高度封装,为了隐藏Http的无状态 ...
- MySQL增删改操作
增删改操作 增加 看语法 1. 插入完整数据(顺序插入) 语法一: INSERT INTO 表名(字段1,字段2,字段3-字段n) VALUES(值1,值2,值3-值n); #指定字段来插入数据,插入 ...
随机推荐
- JavaScript中的String对象详解
1.属性 String对象最常用的属性是length,用于返回字符串对象的长度. 2.方法 CharAt(index) 返回字符串对象中指定索引号组成的字符串,位置的有效值为0到字符串的长度减1. ...
- android中常见的命名及其特点详解
Paseal命名法 Paseal命名法特点:String MyName-DelphiInt MyAge每个单词首字母大写 Camel命名法 Camel(驼峰的意思)命名法特点:String myNam ...
- hdu 1856 More is better (并查集)
More is better Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 327680/102400 K (Java/Others) ...
- LeetCode -- Linked List Circle ii
Question: Given a linked list, return the node where the cycle begins. If there is no cycle, return ...
- 我的emacs配置部分
考场必记8行 (global-set-key (kbd "RET") 'newline-and-indent)//换行 (global-set-key (kbd "C-a ...
- error C3872: '0x3000': this character is not allowed in an identifier 解决方法
文章参考地址:http://blog.csdn.net/danxuezx/article/details/5096497 编译时遇到这个错误多半是从网上拷贝一段代码到VS里然后编译时产生的,这是因为拷 ...
- [Leetcode] Path Sum II路径和
Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given su ...
- 遇到问题---java---git下载的maven项目web用tomcat发布时不带子项目
遇到的情况是用git下载maven项目,然后用mvn eclipse:eclipse命令标记为eclipse项目之后,使用maven插件导入之后用tomcat发布运行,发现maven关联的几个子项目没 ...
- BZOJ_day5
32题...今天颓了不想再写了
- poj2814-拨钟问题-C语言-枚举算法
#include <stdio.h> #include <stdlib.h> /* 首先,我们考虑用长度为9的数组表示表盘的状态以及调表的操作,终止的条件是表盘状态数组所有元素 ...