zoukankan      html  css  js  c++  java
  • easyUi可编辑表格

    //表格展示
    
    $("#tt").datagrid({
        columns:[[
            {field:'itemid',title:'Item ID',80,sortable:true,editor:'text'},
            {field:'productid',title:'Product ID',80,sortable:true,editor:'text'},
            {field:'status',title:'Item Details',editor:'text'},
            {field:'listprice',title:'List Price',80,align:'right',sortable:true,
            editor:'text'
                },
            {field:'unitcost',title:'Unit Cost',80,align:'right',sortable:true,
            styler: function(value,row,index){
                    if (value < 12 || value > 12){
                        return 'color:red;';
                        // the function can return predefined css class and inline style
                        // return {class:'c1',style:'color:red'}
                    }
                }
            },
            {field:'attr1',title:'Attribute',100,formatter: function(value,row,index){
                  if (row.user){
                        return row.user.name;
                    } else {
                        return value;
                    }
                }},
        ]]
    });
        var editIndex = undefined; //全局变量
        var editField = undefined; //全局变量
    //数据网格编辑 $('#tt').datagrid({ onClickCell: function (index, field, value) { //每个文本框都可以编辑 if(endEditing()){ myonClickCell(index, field); } }, }); //自定义编辑 function myonClickCell(index,field){ editIndex = index; editField = field; $('#tt').datagrid('editCell', { index: index, field: field }); }
    
    //结束编辑
        function endEditing(){
        if (editIndex == undefined) { return true; }
                 if ($('#tt').datagrid('validateRow', 100)) {
                 console.log(111);
                    $('#tt').datagrid('endEdit', editIndex);
                     editIndex = undefined;
                     editField = undefined;
                     return true;
                } else {
                return false;
            }
        }
    //下面是单元格编辑方法
        $.extend($.fn.datagrid.methods, {
            editCell: function (jq, param) {
                // console.log(param){index: 3, field: "tb_zkje"};
                    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;
                        }
                    });
                }
         });
  • 相关阅读:
    IOS 模块并且发布到NPM
    处理npm publish报错问题
    IOS 应用发布流程
    《温故而知新》JAVA基础八
    Beta冲刺 (5/7)
    Beta冲刺 (4/7)
    Beta冲刺 (3/7)
    Beta冲刺 (2/7)
    软件测试(团队)
    福大软工 · BETA 版冲刺前准备(团队)
  • 原文地址:https://www.cnblogs.com/zoumin123/p/6347340.html
Copyright © 2011-2022 走看看