zoukankan      html  css  js  c++  java
  • EasyUI DataGrid 编辑单元格

    如下图:

    这里写图片描述

    现改为单击某个单元格只对此单元格进行可编辑

    <TABLE>标记添加 onClickCell

    <table id="dg" class="easyui-datagrid" data-options="onClickCell: onClickCell">

    需要进行编辑的列上添加 editor

    <th data-options="field:'itemId',editor:'numberbox'"></th>

    也可以指定

    • 小数位数:editor:{type:’numberbox’,options:{precision:1}}

    • 文本类型:editor:’text’

    • checkbox:editor:{type:’checkbox’,options:{on:’启动’,off:’关闭’}}

    效果如下:

    这里写图片描述

    核心代码

    <script type="text/javascript">
    
    $.extend($.fn.datagrid.methods, {
        editCell : function(jq, param) {
            return jq.each(function() {
                var opts = $(this).datagrid('options');
                var fields = $(this).datagrid('getColumnFields', true).concat(
                        $(this).datagrid('getColumnFields'));
                for ( var i = 0; i < fields.length; i++) {
                    var col = $(this).datagrid('getColumnOption', fields[i]);
                    col.editor1 = col.editor;
                    if (fields[i] != param.field) {
                        col.editor = null;
                    }
                }
                $(this).datagrid('beginEdit', param.index);
                for ( var i = 0; i < fields.length; i++) {
                    var col = $(this).datagrid('getColumnOption', fields[i]);
                    col.editor = col.editor1;
                }
            });
        }
    });
    
    var editIndex = undefined;
    //结束编辑 
    function endEditing() {
        if (editIndex == undefined) {
            return true
        }
        if ($('#dg').datagrid('validateRow', editIndex)) {
            $('#dg').datagrid('endEdit', editIndex);
            editIndex = undefined;
            return true;
        } else {
            return false;
        }
    }
    //单击单元格 
    function onClickCell(index, field) {
        if (endEditing()) {
            $('#dg').datagrid('selectRow', index).datagrid('editCell', {
                index : index,
                field : field
            });
            editIndex = index;
        }
    }
    </script>
  • 相关阅读:
    每天一道LeetCode--141.Linked List Cycle(链表环问题)
    每天一道LeetCode--119.Pascal's Triangle II(杨辉三角)
    每天一道LeetCode--118. Pascal's Triangle(杨辉三角)
    CF1277D Let's Play the Words?
    CF1281B Azamon Web Services
    CF1197D Yet Another Subarray Problem
    CF1237D Balanced Playlist
    CF1239A Ivan the Fool and the Probability Theory
    CF1223D Sequence Sorting
    CF1228D Complete Tripartite
  • 原文地址:https://www.cnblogs.com/huangf714/p/5898899.html
Copyright © 2011-2022 走看看