李炎恢 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

相关文章

SQL Server修改数据库名及物理数据文件名操作步骤

《SQLServer修改数据库名及物理数据文件名操作步骤》在SQLServer中重命名数据库是一个常见的操作,但需要确保用户具有足够的权限来执行此操作,:本文主要介绍SQLServer修改数据... 目录一、背景介绍二、操作步骤2.1 设置为单用户模式(断开连接)2.2 修改数据库名称2.3 查找逻辑文件名

Python实现精准提取 PDF中的文本,表格与图片

《Python实现精准提取PDF中的文本,表格与图片》在实际的系统开发中,处理PDF文件不仅限于读取整页文本,还有提取文档中的表格数据,图片或特定区域的内容,下面我们来看看如何使用Python实... 目录安装 python 库提取 PDF 文本内容:获取整页文本与指定区域内容获取页面上的所有文本内容获取

canal实现mysql数据同步的详细过程

《canal实现mysql数据同步的详细过程》:本文主要介绍canal实现mysql数据同步的详细过程,本文通过实例图文相结合给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的... 目录1、canal下载2、mysql同步用户创建和授权3、canal admin安装和启动4、canal

使用SpringBoot整合Sharding Sphere实现数据脱敏的示例

《使用SpringBoot整合ShardingSphere实现数据脱敏的示例》ApacheShardingSphere数据脱敏模块,通过SQL拦截与改写实现敏感信息加密存储,解决手动处理繁琐及系统改... 目录痛点一:痛点二:脱敏配置Quick Start——Spring 显示配置:1.引入依赖2.创建脱敏

Spring组件实例化扩展点之InstantiationAwareBeanPostProcessor使用场景解析

《Spring组件实例化扩展点之InstantiationAwareBeanPostProcessor使用场景解析》InstantiationAwareBeanPostProcessor是Spring... 目录一、什么是InstantiationAwareBeanPostProcessor?二、核心方法解

详解如何使用Python构建从数据到文档的自动化工作流

《详解如何使用Python构建从数据到文档的自动化工作流》这篇文章将通过真实工作场景拆解,为大家展示如何用Python构建自动化工作流,让工具代替人力完成这些数字苦力活,感兴趣的小伙伴可以跟随小编一起... 目录一、Excel处理:从数据搬运工到智能分析师二、PDF处理:文档工厂的智能生产线三、邮件自动化:

Python数据分析与可视化的全面指南(从数据清洗到图表呈现)

《Python数据分析与可视化的全面指南(从数据清洗到图表呈现)》Python是数据分析与可视化领域中最受欢迎的编程语言之一,凭借其丰富的库和工具,Python能够帮助我们快速处理、分析数据并生成高质... 目录一、数据采集与初步探索二、数据清洗的七种武器1. 缺失值处理策略2. 异常值检测与修正3. 数据

pandas实现数据concat拼接的示例代码

《pandas实现数据concat拼接的示例代码》pandas.concat用于合并DataFrame或Series,本文主要介绍了pandas实现数据concat拼接的示例代码,具有一定的参考价值,... 目录语法示例:使用pandas.concat合并数据默认的concat:参数axis=0,join=

C#代码实现解析WTGPS和BD数据

《C#代码实现解析WTGPS和BD数据》在现代的导航与定位应用中,准确解析GPS和北斗(BD)等卫星定位数据至关重要,本文将使用C#语言实现解析WTGPS和BD数据,需要的可以了解下... 目录一、代码结构概览1. 核心解析方法2. 位置信息解析3. 经纬度转换方法4. 日期和时间戳解析5. 辅助方法二、L

使用Python和Matplotlib实现可视化字体轮廓(从路径数据到矢量图形)

《使用Python和Matplotlib实现可视化字体轮廓(从路径数据到矢量图形)》字体设计和矢量图形处理是编程中一个有趣且实用的领域,通过Python的matplotlib库,我们可以轻松将字体轮廓... 目录背景知识字体轮廓的表示实现步骤1. 安装依赖库2. 准备数据3. 解析路径指令4. 绘制图形关键