<!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">
    <title>jQuery EasyUI</title>
    <link rel="stylesheet" type="text/css" href="../themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="../themes/icon.css">
    <script type="text/javascript" src="../jquery-1.4.2.min.js"></script>
    <script type="text/javascript" src="../jquery.easyui.min.js"></script>
    <script>
        var users = {total:6,rows:[
            {no:1,name:'用户1',addr:'山东济南',email:'user1@163.com',birthday:'1/1/1980'},
            {no:2,name:'用户2',addr:'山东济南',email:'user2@163.com',birthday:'1/1/1980'},
            {no:3,name:'用户3',addr:'山东济南',email:'user3@163.com',birthday:'1/1/1980'},
            {no:4,name:'用户4',addr:'山东济南',email:'user4@163.com',birthday:'1/1/1980'},
            {no:5,name:'用户5',addr:'山东济南',email:'user5@163.com',birthday:'1/1/1980'},
            {no:6,name:'用户6',addr:'山东济南',email:'user6@163.com',birthday:'1/1/1980'}
        ]};
        $(function(){
            $('#tt').datagrid({
                title:'Editable DataGrid',
                iconCls:'icon-edit',
                width:530,
                height:250,
                singleSelect:true,
                columns:[[
                    {field:'no',title:'编号',width:50,editor:'numberbox'},
                    {field:'name',title:'名称',width:60,editor:'text'},
                    {field:'addr',title:'地址',width:100,editor:'text'},
                    {field:'email',title:'电子邮件',width:100,
                        editor:{
                            type:'validatebox',
                            options:{
                                validType:'email'
                            }
                        }
                    },
                    {field:'birthday',title:'生日',width:80,editor:'datebox'},
                    {field:'action',title:'操作',width:70,align:'center',
                        formatter:function(value,row,index){
                            if (row.editing){
                                var s = '<a href="#" onclick="saverow('+index+')">保存</a> ';
                                var c = '<a href="#" onclick="cancelrow('+index+')">取消</a>';
                                return s+c;
                            } else {
                                var e = '<a href="#" onclick="editrow('+index+')">编辑</a> ';
                                var d = '<a href="#" onclick="deleterow('+index+')">删除</a>';
                                return e+d;
                            }
                        }
                    }
                ]],
                toolbar:[{
                    text:'增加',
                    iconCls:'icon-add',
                    handler:addrow
                },{
                    text:'保存',
                    iconCls:'icon-save',
                    handler:saveall
                },{
                    text:'取消',
                    iconCls:'icon-cancel',
                    handler:cancelall
                }],
                onBeforeEdit:function(index,row){
                    row.editing = true;
                    $('#tt').datagrid('refreshRow', index);
                    editcount++;
                },
                onAfterEdit:function(index,row){
                    row.editing = false;
                    $('#tt').datagrid('refreshRow', index);
                    editcount--;
                },
                onCancelEdit:function(index,row){
                    row.editing = false;
                    $('#tt').datagrid('refreshRow', index);
                    editcount--;
                }
            }).datagrid('loadData',users).datagrid('acceptChanges');
        });
        var editcount = 0;
        function editrow(index){
            $('#tt').datagrid('beginEdit', index);
        }
        function deleterow(index){
            $.messager.confirm('确认','是否真的删除?',function(r){
                if (r){
                    $('#tt').datagrid('deleteRow', index);
                }
            });
        }
        function saverow(index){
            $('#tt').datagrid('endEdit', index);
        }
        function cancelrow(index){
            $('#tt').datagrid('cancelEdit', index);
        }
        function addrow(){
            if (editcount > 0){
                $.messager.alert('警告','当前还有'+editcount+'记录正在编辑,不能增加记录。');
                return;
            }
            $('#tt').datagrid('appendRow',{
                no:'',
                name:'',
                addr:'',
                email:'',
                birthday:''
            });
        }
        function saveall(){
            $('#tt').datagrid('acceptChanges');
        }
        function cancelall(){
            $('#tt').datagrid('rejectChanges');
        }
    </script>
</head>
<body>
<h1>Editable DataGrid</h1>
<table id="tt"></table>
</body>
</html>

在jQuery EasyUI中实现对DataGrid进行编辑的更多相关文章

  1. JQuery EasyUI中datagrid的使用

    在学习过程中,可以参照JQuery EasyUI的官方网站学习.地址:http://www.jeasyui.com/demo/main/index.php 在学习JQuery EasyUI中的Data ...

  2. 在应用程序中实现对NandFlash的操作

    以TC58NVG2S3ETA00 为例: 下面是它的一些物理参数: 图一 图二 图三 图四 图五 图6-0 图6-1 说明一下,在图6-1中中间的那个布局表可以看做是实际的NandFlash一页数据的 ...

  3. C++中实现对map按照value值进行排序 - 菜鸟变身记 - 51CTO技术博客

    C++中实现对map按照value值进行排序 - 菜鸟变身记 - 51CTO技术博客 C++中实现对map按照value值进行排序 2012-03-15 15:32:36 标签:map 职场 休闲 排 ...

  4. Jquery EasyUI中treegrid

    Jquery EasyUI中treegrid的中右键菜单和一般按钮同时绑定事件时的怪异事件 InChatter系统开源聊天模块前奏曲   最近在研究WCF,又因为工作中的项目需要,要为现有的系统增加一 ...

  5. Android平台中实现对XML的三种解析方式

    本文介绍在Android平台中实现对XML的三种解析方式. XML在各种开发中都广泛应用,Android也不例外.作为承载数据的一个重要角色,如何读写XML成为Android开发中一项重要的技能. 在 ...

  6. jquery easyUI中combobox的使用总结

    jquery easyUI中combobox的使用总结 一.如何让jquery-easyui的combobox像select那样不可编辑?为combobox添加editable属性 设置为false ...

  7. 求助关于jquery easyUI中的treegrid组件,请各位帮忙给个思路,谢谢啦

    现在项目中用到jquery easyUI中的treegrid组件,已经可以正常显示了.但是在保存的时候遇到问题,页面上参照官网的例子可以在页面更新,但是怎么获取编辑后的数据进而保存到数据库呢?

  8. Python中实现对list做减法操作介绍

    Python中实现对list做减法操作介绍 这篇文章主要介绍了Python中实现对list做减法操作介绍,需要的朋友可以参考下 问题描述:假设我有这样两个list, 一个是list1,list1 = ...

  9. 雷林鹏分享:jQuery EasyUI 数据网格 - 启用行内编辑

    jQuery EasyUI 数据网格 - 启用行内编辑 可编辑的功能是最近添加到数据网格(datagrid)的.它可以使用户添加一个新行到数据网格(datagrid).用户也可以更新一个或多个行. 本 ...

随机推荐

  1. 爬虫学习----pattern

    1.match match(string[, pos[, endpos]]) | re.match(pattern, string[, flags]): 这个方法将从string的pos下标处起尝试匹 ...

  2. 省赛13 Alice and Bob(二进制,找规律)

    题意:多项式相乘,(a0x+1)(a1x^2+1)(a2x^4+1),问x的m次方的系数是多少,当时没做出来,搜的某大神的博客,好理解. 思路:多列几个式子就能明白规律了: (a0x+1)(a1x^2 ...

  3. mysql 远程连接失败(linux)

    主要有三个原因:1.mysql授权表里没有远程机器的权限,及需要在授权表mysql.user添加grant all privileges on *.* to 'root'@'远程登陆IP' ident ...

  4. Inno如何在安装完成时删除指定的文件夹(下的所有文件及子目录)??

    删除安装目录下的任意文件夹及下的所有文件及子目录,或者删除指定目录的文件夹,要如何做到呢?谢谢!! //删除文件    用 DeleteFile 只能删除一个文件,不能使用通配符来删除多个文件Dele ...

  5. sourceMappingURL

    JavaScript Source Map 详解

  6. IE6无法加载CSS

    问题:写了个页面,IE7和IE8下正常,但发现IE6下竟然没有加载css样式. 找原因,发现是因为CSS文件的编码不正确,页面是采用utf-8编码的,但样式表是复制过来的,编码是ANSI,这种情况下在 ...

  7. 学习Linux——计算机概论

    一直想学习Linux,但计划时不时被耽误,现在开始,决定每天开始学习Linux.学习从最简单的开始,一步步,不能将最简单的东西忽略. 1.计算机硬件的五大单元 计算机分为三部分:输入单元,中央处理器即 ...

  8. 光流算法:Brox算法(转载)

    参考论文:1. High Accuracy Optical Flow Estimation Based on a Theory for Warping, Thomas Box, ECCV20042. ...

  9. html5之我見

    大多數知道html5的國人,不限於IT業內人員,對Html5存在較大誤解. 幾天前在新浪微博看到一個ID為"黑客師"的微博發佈了一張照片,名為"小白與高手的差別" ...

  10. C#使用指针的2个主要原因

    一下内容来自于书籍:<C#高级编程(第六版)> C#使用指针的2个主要原因: