Loading [MathJax]/jax/input/TeX/config.js
前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >jquery.edatagrid(可编辑datagrid)的使用

jquery.edatagrid(可编辑datagrid)的使用

作者头像
用户1141560
发布于 2017-12-26 07:38:55
发布于 2017-12-26 07:38:55
1.5K00
代码可运行
举报
文章被收录于专栏:西安-晁州西安-晁州
运行总次数:0
代码可运行

用spring+springmvc+mybatis+mysql实现简单的可编辑单元格,首先是页面效果图:

其中,“编号”列是不可编辑的,“暂缓措施”是可以自由编辑的,主要html组成:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/jquery-easyui-1.3.3/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/jquery-easyui-1.3.3/themes/icon.css">
<script type="text/javascript" src="${pageContext.request.contextPath}/jquery-easyui-1.3.3/jquery.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/jquery-easyui-1.3.3/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/jquery-easyui-1.3.3/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/jquery-easyui-1.3.3/jquery.edatagrid.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/common.js"></script>
<script type="text/javascript">
 
 $(function(){
     $("#dg").edatagrid({
        url:'${pageContext.request.contextPath}/customerReprieve/list.do?lossId=${param.lossId}',
        saveUrl:'${pageContext.request.contextPath}/customerReprieve/save.do?customerLoss.id=${param.lossId}',
        updateUrl:'${pageContext.request.contextPath}/customerReprieve/save.do',
        destroyUrl:'${pageContext.request.contextPath}/customerReprieve/delete.do'
     });
 });
 
 function confirmLoss(){
     $.messager.prompt('系统提示', '请输入流失原因:', function(r){
            if (r){
                $.post("${pageContext.request.contextPath}/customerLoss/confirmLoss.do",{id:'${param.lossId}',lossReason:r},function(result){
                    if(result.success){
                         $.messager.alert("系统提示","执行成功!");
                    }else{
                        $.messager.alert("系统提示","执行失败!");
                    }
                },"json");
            }
        });
 }
 
</script>
<title>Insert title here</title>
</head>
<body style="margin: 15px">
 
 <table id="dg" title="客户流失暂缓措施管理" style="width:800px;height:250px"
   toolbar="#toolbar" idField="id" rownumbers="true" fitColumns="true" singleSelect="true">
   <thead>
       <tr>
           <th field="id" width="50">编号</th>
           <th field="measure" width="300" editor="{type:'validatebox',options:{required:true}}">暂缓措施</th>
       </tr>
   </thead>
 </table>
 
 <div id="toolbar">
     <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="javascript:$('#dg').edatagrid('addRow')">添加</a>
     <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="javascript:$('#dg').edatagrid('destroyRow')">删除</a>
     <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-save" plain="true" onclick="javascript:$('#dg').edatagrid('saveRow');$('#dg').edatagrid('reload')">保存</a>
     <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-undo" plain="true" onclick="javascript:$('#dg').edatagrid('cancelRow')">撤销行</a>
     <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-confirm" plain="true" onclick="javascript:confirmLoss()">确认流失</a>
 </div>
</body>
</html>

edatagrid中定义了四个url属性,代表四种操作的请求路径,分别为url(列表查询url)、saveUrl(更新保存url)、updateUrl(新增保存url)、deleteUrl(删除url)

主要的controller实现:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
/**
 * 客户流失暂缓措施Controller层
 * @author Administrator
 *
 */
@Controller
@RequestMapping("/customerReprieve")
public class CustomerReprieveController {
    
    @Resource
    private CustomerReprieveService customerReprieveService;
     
    /**
     * 分页条件查询客户流失暂缓措施
     * @param page
     * @param rows
     * @param s_customerReprieve
     * @param response
     * @return
     * @throws Exception
     */
    @RequestMapping("/list")
    public String list(@RequestParam(value="lossId",required=false)String lossId,HttpServletResponse response)throws Exception{
        Map<String,Object> map=new HashMap<String,Object>();
        map.put("lossId", lossId);
        List<CustomerReprieve> customerReprieveList=customerReprieveService.find(map);
        JSONObject result=new JSONObject();
        JsonConfig jsonConfig=new JsonConfig();
        jsonConfig.setExcludes(new String[]{"customerLoss"});
        JSONArray jsonArray=JSONArray.fromObject(customerReprieveList,jsonConfig);
        result.put("rows", jsonArray);
        ResponseUtil.write(response, result);
        return null;
    }
    
    /**
     * 添加或者修改客户流失暂缓措施
     * @param customerReprieve
     * @param response
     * @return
     * @throws Exception
     */
    @RequestMapping("/save")
    public String save(CustomerReprieve customerReprieve,HttpServletResponse response)throws Exception{
        int resultTotal=0; // 操作的记录条数
        if(customerReprieve.getId()==null){
            resultTotal=customerReprieveService.add(customerReprieve);
        }else{
            resultTotal=customerReprieveService.update(customerReprieve);
        }
        JSONObject result=new JSONObject();
        if(resultTotal>0){
            result.put("success", true);
        }else{
            result.put("success", false);
        }
        ResponseUtil.write(response, result);
        return null;
    }
    
    /**
     * 删除客户流失暂缓措施
     * @param ids
     * @param response
     * @return
     * @throws Exception
     */
    @RequestMapping("/delete")
    public String delete(@RequestParam(value="id")String id,HttpServletResponse response)throws Exception{
        customerReprieveService.delete(Integer.parseInt(id));
        JSONObject result=new JSONObject();
        result.put("success", true);
        ResponseUtil.write(response, result);
        return null;
    }
}

CustomerReprieveService(接口及实现类)主要实现:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
/**
 * 客户流失暂缓措施Service接口
 * @author Administrator
 *
 */
public interface CustomerReprieveService {

    
    /**
     * 查询客户流失暂缓措施集合
     * @param map
     * @return
     */
    public List<CustomerReprieve> find(Map<String,Object> map);
    
    
    /**
     * 获取总记录数
     * @param map
     * @return
     */
    public Long getTotal(Map<String,Object> map);
    
    /**
     * 修改客户流失暂缓措施
     * @param customerReprieve
     * @return
     */
    public int update(CustomerReprieve customerReprieve);
    
    /**
     * 添加客户流失暂缓措施
     * @param customerReprieve
     * @return
     */
    public int add(CustomerReprieve customerReprieve);
    
    /**
     * 删除客户流失暂缓措施
     * @param id
     * @return
     */
    public int delete(Integer id);
    
}
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
/**
 * 客户流失暂缓措施Service实现类
 * @author Administrator
 *
 */
@Service("customerReprieveService")
public class CustomerReprieveServiceImpl implements CustomerReprieveService{

    @Resource
    private CustomerReprieveDao CustomerReprieveDao;
    
    @Override
    public List<CustomerReprieve> find(Map<String, Object> map) {
        return CustomerReprieveDao.find(map);
    }

    @Override
    public Long getTotal(Map<String, Object> map) {
        return CustomerReprieveDao.getTotal(map);
    }

    @Override
    public int update(CustomerReprieve customerReprieve) {
        return CustomerReprieveDao.update(customerReprieve);
    }

    @Override
    public int add(CustomerReprieve customerReprieve) {
        return CustomerReprieveDao.add(customerReprieve);
    }

    @Override
    public int delete(Integer id) {
        return CustomerReprieveDao.delete(id);
    }

}

接下来是dao层实现:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
/**
 * 客户流失暂缓措施Dao接口
 * @author Administrator
 *
 */
public interface CustomerReprieveDao {

    
    /**
     * 查询客户流失暂缓措施集合
     * @param map
     * @return
     */
    public List<CustomerReprieve> find(Map<String,Object> map);
    
    
    /**
     * 获取总记录数
     * @param map
     * @return
     */
    public Long getTotal(Map<String,Object> map);
    
    /**
     * 修改客户流失暂缓措施
     * @param customerReprieve
     * @return
     */
    public int update(CustomerReprieve customerReprieve);
    
    /**
     * 添加客户流失暂缓措施
     * @param customerReprieve
     * @return
     */
    public int add(CustomerReprieve customerReprieve);
    
    /**
     * 删除客户流失暂缓措施
     * @param id
     * @return
     */
    public int delete(Integer id);
    
}

因为采用的是mybatis进行ORM映射,所以不必手动写sql,主要映射文件如下:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.dao.CustomerReprieveDao">

    <resultMap type="CustomerReprieve" id="CustomerReprieveResult">
        <result property="id" column="id"/>
        <result property="measure" column="measure"/>
        <association property="customerLoss" column="lossId" select="com.dao.CustomerLossDao.findById"></association>
    </resultMap>
    
    <select id="find" parameterType="Map" resultMap="CustomerReprieveResult">
        select * from t_customer_reprieve
        <where>
            <if test="lossId!=null and lossId!='' ">
                and lossId = #{lossId}
            </if>
        </where>
        <if test="start!=null and size!=null">
            limit #{start},#{size}
        </if>
    </select>

    
    <select id="getTotal" parameterType="Map" resultType="Long">
        select count(*) from t_customer_reprieve
        <where>
            <if test="lossId!=null and lossId!='' ">
                and lossId = #{lossId}
            </if>
        </where>
    </select>
    
    <insert id="add" parameterType="CustomerReprieve">
        insert into t_customer_reprieve values(null,#{customerLoss.id},#{measure})
    </insert>
    
    <update id="update" parameterType="CustomerReprieve">
        update t_customer_reprieve
        <set>
            <if test="measure!=null and measure!='' ">
                measure=#{measure},
            </if>
        </set>
        where id=#{id}
    </update>
    
    <delete id="delete" parameterType="Integer">
        delete from t_customer_reprieve where id=#{id}
    </delete>
    
</mapper> 
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2015-11-11 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
day51_BOS项目_03
将上面的js文件引入所需要的jsp页面中,本例以index.jsp为例 /bos19/WebContent/WEB-INF/pages/common/index.jsp
黑泽君
2018/10/11
3.4K0
day51_BOS项目_03
SpringMVC+easyUI CRUD 添加数据C
接一篇文章,今天上午实现了添加数据。以下是Jsp。里面主要是看newUser()和saveUser().注意这函数里的url,newUser()里面去掉url属性。还要注意的一个问题
全栈程序员站长
2022/07/08
2460
jquery easyui datagrid 保存/加载自定义配置每列属性
直接附上源代码 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Format DataGrid Columns - jQuery EasyUI Demo</title> <link rel="stylesheet" type="text/css" href="css/material/easyui.css"> <script type="text/javascript" src="js/jquery.mi
阿新
2019/10/06
1.3K0
【Jqurey EasyUI+Asp.net】—DataGrid增加、删、更改、搜
在前面写了两,但不知道如何完成,对比刚刚开始学这个,他们摸着石头过河,一步步。在最后两天DataGridCRUD融合在一起。因此份额。我希望像我这样谁是刚刚开始学习一些帮助。
全栈程序员站长
2022/07/06
1.4K0
【ssm个人博客项目实战02】easy UI搭建后台管理界面基于easy UI搭建后台界面
前面一节我们已经成功搭建ssm项目的环境,接下来我们需要做的就是搭建我们后台管理界面的框架。 这搭建完之后的效果图
yukong
2018/08/21
1.6K0
【ssm个人博客项目实战02】easy UI搭建后台管理界面基于easy UI搭建后台界面
使用SSM+easyui做个简单的增删改查
使用SSM+easyui做个简单的增删改查
Java架构师必看
2021/04/13
1.9K0
nodejs操作excel并配合edatagrid使用
nodejs读取文件夹下子文件(夹)名称: /** * 查询tmp文件夹下子文件夹名称 */ router.post("/tmpList", function (req, res) { f
用户1141560
2017/12/26
1.5K0
nodejs操作excel并配合edatagrid使用
Spring Boot 之整合 EasyUI 打造 Web 应用
EasyUI 下载地址:http://www.jeasyui.cn/download.html
静默虚空
2022/03/23
8130
easyui+nodejs+sqlserver增删改查实现
用到的模块或者技术: Express: http://www.expressjs.com.cn/4x/api.html#express Easyui: http://www.jeasyui.com
用户1141560
2017/12/26
3.1K0
easyui+nodejs+sqlserver增删改查实现
very-easyUI 框架快速上手文档
这是我自己闲暇之余封装的一个工具,当然还有一大堆BUG,但是对于自己接接小活还是挺方便的,分享出来。后面会慢慢持续更新。
剽悍一小兔
2019/10/10
1.7K0
very-easyUI 框架快速上手文档
ASP.NET MVC5+EF6+EasyUI 后台管理系统(82)-Easyui Datagrid批量操作(编辑,删除,添加)
前言 有时候我们的后台系统表单比较复杂,做过进销存或者一些销售订单的都应该有过感觉 虽然Easyui Datagrid提供了行内编辑,但是不够灵活,但是我们稍微修改一下来达到批量编辑,批量删除,批
用户1149182
2018/01/12
1.8K0
ASP.NET MVC5+EF6+EasyUI 后台管理系统(82)-Easyui Datagrid批量操作(编辑,删除,添加)
探索 JQuery EasyUI:构建简单易用的前端页面
当我们站在网页开发的浩瀚世界中,眼花缭乱的选择让我们难以抉择。而就在这纷繁复杂的技术海洋中,JQuery EasyUI 如一位指路明灯,为我们提供了一条清晰的航线。
繁依Fanyi
2024/04/25
7930
javaWeb核心技术第十四篇之easyui
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
海仔
2019/09/18
1.2K0
thinkjs crud练习
该文章介绍了一种使用 ES6 实现模板引擎,并使用 ThinkJS 引擎进行模板渲染的方法。该方法包括配置 ES6 环境、定义模板引擎接口、实现模板引擎基类、定义模板语法、实现模板编译和渲染、编写测试用例和代码示例。
用户1141560
2017/12/26
1.5K0
thinkjs crud练习
javaweb权限管理简单实现_开源权限管理框架
注:由于该项目比较老,所以没有采用maven管理,建议下载java后台通用权限管理系统(springboot)),对学习和使用会更有帮助。
全栈程序员站长
2022/09/28
1.3K0
javaweb权限管理简单实现_开源权限管理框架
day49_BOS项目_01
其余步骤参考如下链接: https://www.cnblogs.com/chenmingjun/p/9513143.html#_label0 右键项目 --> Team --> Share Project…
黑泽君
2018/10/11
1.1K0
day49_BOS项目_01
Web-第二十三天 Web商城实战三【悟空教程】
Web-第二十三天 Web商城实战三【悟空教程】 网上商城实战三 今日内容介绍 订单管理/我的订单 订单管理/订单详情 订单管理/在线支付 权限过滤器 后台页面搭建 后台分类管理 后台商品管理 项目
Java帮帮
2018/07/27
9530
Web-第二十三天 Web商城实战三【悟空教程】
商城项目整理(四)JDBC+富文本编辑器实现商品增加,样式设置,和修改
UEditor富文本编辑器:http://ueditor.baidu.com/website/ 相应页面展示: 商品添加: 商品修改: 前台商品展示: 商品表建表语句: 1 create table
二十三年蝉
2018/02/28
2.6K0
商城项目整理(四)JDBC+富文本编辑器实现商品增加,样式设置,和修改
day50_BOS项目_02
我们再补上IUserDao和UserDaoImpl的示例代码: IUserDao.java
黑泽君
2018/10/11
1.6K0
day50_BOS项目_02
商城项目回顾整理(二)easyUi数据表格使用
后台主页: 商品的数据表格展示 引入用户表数据表格展示 引入日志表数据表格展示 引入订单表数据表格展示 后台主页代码: 1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8" 3 import="com.hanqi.model.Log,java.net.UnknownHostException,java.net.InetAddress,java.util.*,
二十三年蝉
2018/02/28
1.3K0
推荐阅读
相关推荐
day51_BOS项目_03
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
本文部分代码块支持一键运行,欢迎体验
本文部分代码块支持一键运行,欢迎体验