李炎恢 DataGrid(数据表格)组件[5] 添加数据

2024-04-11 19:48

本文主要是介绍李炎恢 DataGrid(数据表格)组件[5] 添加数据,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>DataGrid(数据表格)组件[5] 添加数据</title>
    <script src="~/easyui/jquery.min.js"></script>
    <script src="~/easyui/jquery.easyui.min.js"></script>
    <script src="~/easyui/locale/easyui-lang-zh_CN.js"></script>
    <link href="~/easyui/themes/gray/easyui.css" rel="stylesheet" />
    <link href="~/easyui/themes/icon.css" rel="stylesheet" />
    <style type="text/css">
        /*文本框样式*/
        .textbox {
            height: 20px;  
            margin: 0;
            padding: 0 2px;
            box-sizing: content-box;
        }

    </style>
    <script type="text/javascript">

        //扩展 dateTimeBox
        $.extend($.fn.datagrid.defaults.editors, {
            datetimebox: {
                init: function (container, options) {
                    var input = $('<input type="text">').appendTo(container);
                    options.editable = false;
                    input.datetimebox(options);
                    return input;
                },
                getValue: function (target) {
                    return $(target).datetimebox('getValue');
                },
                setValue: function (target, value) {
                    $(target).datetimebox('setValue', value);
                },
                resize: function (target, width) {
                    $(target).datetimebox('resize', width);
                },
                destroy: function (target) {
                    $(target).datetimebox('destroy');
                },
            }
        });

        $(function () {
            //全局对象
            obj = {
                editRow: false,


                add:function()
                {
                    if (!this.editRow) //没有新编辑行
                    {
                        $('#save,#redo').show();

                        //添加一行
                        $('#box').datagrid("insertRow", {
                            index: 0,
                            row: {

                            },
                        });

                        //将第1行设置为可编辑状态
                        $('#box').datagrid("beginEdit", 0);

                        this.editRow = true;
                    }

                },

 

 

                save: function () {
                    //这两句不应该放这里,应该是保存成功后,再执行
                    //$('#save,#redo').hide();
                    //this.editRow = false;
                    //将第一行设置为结束编辑状态
                    $('#box').datagrid('endEdit', 0);
                },


                redo: function () {
                    $('#save,#redo').hide();
                    this.editRow = false;
                    $('#box').datagrid('rejectChanges'); //回滚
                },

 

 

            };

            $('#box').datagrid({
                width: 800,
                title: '用户列表',
                iconCls: 'icon-search',
                toolbar: '#tb', //工具条
                //url:'Home/a', //数据地址
                striped: true,
                nowrap: true,
                rownumbers: true,
                singleSelect: true,
                fitColumns: true,
                columns: [[
                    {
                        field: 'user',
                        title: '帐号',
                        width: 100,
                        editor: {
                            type: 'validatebox',
                            options: {
                                required:true, //属性
                            }
                        },

                    },
                    {
                        field: 'email',
                        title: '邮件',
                        width: 100,
                        editor: {
                            type: 'validatebox',
                            options: {
                                required: true,
                                validType:'email',
                            }
                        },
                    },
                    {
                        field: 'date',
                        title: '注册时间',
                        editable: false,
                        width: 100,
                        editor: {
                            //type: 'datebox',
                            type: 'datetimebox',
                            options: {
                                required: true,
                            },
                        },
                    },
                ]],
                onAfterEdit: function (rowIndex, rowData, changes) {
                    $('#save,#redo').hide();
                    obj.editRow = false;
                    console.log(rowData); //保存到数据库
                },

            });
        });
    </script>

</head>
<body>
    <table id="box">
    </table>
    <div id="tb" style="padding:5px;height:auto">
        <div style="margin-bottom:5px"> 
            <a href="#" class="easyui-linkbutton" iconcls="icon-add" plain="true" οnclick="obj.add();">添加</a> 
            <a href="#" class="easyui-linkbutton" iconcls="icon-edit" plain="true">修改</a> 
            <a href="#" class="easyui-linkbutton" iconcls="icon-remove" plain="true">删除</a> 
            <a href="#" class="easyui-linkbutton" iconcls="icon-save" plain="true" style="display:none;" id="save" οnclick="obj.save();">保存 </a> 
            <a href="#" class="easyui-linkbutton" iconcls="icon-redo" plain="true" style="display:none;" id="redo" οnclick="obj.redo();">取消编 辑</a>
        </div> 
        
        <div style="padding:0 0 0 7px;">
            查 询 帐 号 : <input class="textbox" name="user" style="width:110px">
            创 建 时 间 从 : <input class="easyui-datebox" name="date_from" editable="false" style="width:110px"> 
            到 : <input class="easyui-datebox" name="date_to" style="width:110px"> 
            <a href="#" class="easyui-linkbutton" iconcls="icon-search" οnclick="obj.search();">查询</a>
        </div>
    </div>
</body>
</html>

这篇关于李炎恢 DataGrid(数据表格)组件[5] 添加数据的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/895018

相关文章

MySQL数据脱敏的实现方法

《MySQL数据脱敏的实现方法》本文主要介绍了MySQL数据脱敏的实现方法,包括字符替换、加密等方法,通过工具类和数据库服务整合,确保敏感信息在查询结果中被掩码处理,感兴趣的可以了解一下... 目录一. 数据脱敏的方法二. 字符替换脱敏1. 创建数据脱敏工具类三. 整合到数据库操作1. 创建服务类进行数据库

MySQL中处理数据的并发一致性的实现示例

《MySQL中处理数据的并发一致性的实现示例》在MySQL中处理数据的并发一致性是确保多个用户或应用程序同时访问和修改数据库时,不会导致数据冲突、数据丢失或数据不一致,MySQL通过事务和锁机制来管理... 目录一、事务(Transactions)1. 事务控制语句二、锁(Locks)1. 锁类型2. 锁粒

Qt中实现多线程导出数据功能的四种方式小结

《Qt中实现多线程导出数据功能的四种方式小结》在以往的项目开发中,在很多地方用到了多线程,本文将记录下在Qt开发中用到的多线程技术实现方法,以导出指定范围的数字到txt文件为例,展示多线程不同的实现方... 目录前言导出文件的示例工具类QThreadQObject的moveToThread方法实现多线程QC

SpringBoot集成EasyExcel实现百万级别的数据导入导出实践指南

《SpringBoot集成EasyExcel实现百万级别的数据导入导出实践指南》本文将基于开源项目springboot-easyexcel-batch进行解析与扩展,手把手教大家如何在SpringBo... 目录项目结构概览核心依赖百万级导出实战场景核心代码效果百万级导入实战场景监听器和Service(核心

使用Python开发一个Ditto剪贴板数据导出工具

《使用Python开发一个Ditto剪贴板数据导出工具》在日常工作中,我们经常需要处理大量的剪贴板数据,下面将介绍如何使用Python的wxPython库开发一个图形化工具,实现从Ditto数据库中读... 目录前言运行结果项目需求分析技术选型核心功能实现1. Ditto数据库结构分析2. 数据库自动定位3

pandas数据的合并concat()和merge()方式

《pandas数据的合并concat()和merge()方式》Pandas中concat沿轴合并数据框(行或列),merge基于键连接(内/外/左/右),concat用于纵向或横向拼接,merge用于... 目录concat() 轴向连接合并(1) join='outer',axis=0(2)join='o

批量导入txt数据到的redis过程

《批量导入txt数据到的redis过程》用户通过将Redis命令逐行写入txt文件,利用管道模式运行客户端,成功执行批量删除以Product*匹配的Key操作,提高了数据清理效率... 目录批量导入txt数据到Redisjs把redis命令按一条 一行写到txt中管道命令运行redis客户端成功了批量删除k

SpringBoot多环境配置数据读取方式

《SpringBoot多环境配置数据读取方式》SpringBoot通过环境隔离机制,支持properties/yaml/yml多格式配置,结合@Value、Environment和@Configura... 目录一、多环境配置的核心思路二、3种配置文件格式详解2.1 properties格式(传统格式)1.

解决pandas无法读取csv文件数据的问题

《解决pandas无法读取csv文件数据的问题》本文讲述作者用Pandas读取CSV文件时因参数设置不当导致数据错位,通过调整delimiter和on_bad_lines参数最终解决问题,并强调正确参... 目录一、前言二、问题复现1. 问题2. 通过 on_bad_lines=‘warn’ 跳过异常数据3

C#监听txt文档获取新数据方式

《C#监听txt文档获取新数据方式》文章介绍通过监听txt文件获取最新数据,并实现开机自启动、禁用窗口关闭按钮、阻止Ctrl+C中断及防止程序退出等功能,代码整合于主函数中,供参考学习... 目录前言一、监听txt文档增加数据二、其他功能1. 设置开机自启动2. 禁止控制台窗口关闭按钮3. 阻止Ctrl +