• easyui datagrid 行编辑功能


    datagrid现在具有行编辑能力了,使用时只须在columns中为需要编辑的列添加一个editor属性,编辑保存时同时具有数据校验能力。

    看一个例子效果图:

      代码如下:

    $('#tt').datagrid({
        title:'Editable DataGrid',
        iconCls:'icon-edit',
        660,
        height:250,
        singleSelect:true,
        idField:'itemid',
        url:'datagrid_data.json',
        columns:[[
            {field:'itemid',title:'Item ID',60},
            {field:'productid',title:'Product',100,
                formatter:function(value){
                    for(var i=0; i<products.length; i++){
                        if (products[i].productid == value) return products[i].name;
                    }
                    return value;
                },
                editor:{
                    type:'combobox',
                    options:{
                        valueField:'productid',
                        textField:'name',
                        data:products,
                        required:true
                    }
                }
            },
            {field:'listprice',title:'List Price',80,align:'right',editor:{type:'numberbox',options:{precision:1}}},
            {field:'unitcost',title:'Unit Cost',80,align:'right',editor:'numberbox'},
            {field:'attr1',title:'Attribute',150,editor:'text'},
            {field:'status',title:'Status',50,align:'center',
                editor:{
                    type:'checkbox',
                    options:{
                        on: 'P',
                        off: ''
                    }
                }
            },
            {field:'action',title:'Action',70,align:'center',
                formatter:function(value,row,index){
                    if (row.editing){
                        var s = '<a href="#" onclick="saverow('+index+')">Save</a> ';
                        var c = '<a href="#" onclick="cancelrow('+index+')">Cancel</a>';
                        return s+c;
                    } else {
                        var e = '<a href="#" onclick="editrow('+index+')">Edit</a> ';
                        var d = '<a href="#" onclick="deleterow('+index+')">Delete</a>';
                        return e+d;
                    }
                }
            }
        ]],
        onBeforeEdit:function(index,row){
            row.editing = true;
            $('#tt').datagrid('refreshRow', index);
        },
        onAfterEdit:function(index,row){
            row.editing = false;
            $('#tt').datagrid('refreshRow', index);
        },
        onCancelEdit:function(index,row){
            row.editing = false;
            $('#tt').datagrid('refreshRow', index);
        }
    });
    
  • 相关阅读:
    8.14-T1村通网(pupil)
    8.10-Day2T3 镇守府
    8.10-Day2T2 吃喝大法好
    8.10-Day2T1最小值
    8.10-DayT3游走(wander)
    8.10-Day1T2圈(circle)
    8.10-Day1T1-数字(number)
    bzoj2462: [BeiJing2011]矩阵模板
    8.7-Day1T1
    k8s高可用部署后续:SLB
  • 原文地址:https://www.cnblogs.com/babietongtianta/p/3765484.html
Copyright © 2020-2023  润新知