首页 > 代码库 > EasyUI,对treegrid进行编辑

EasyUI,对treegrid进行编辑

主从表,从表是一个treegrid,加载完数据后,点击节点进入编辑状态。

columns : [ [ {
            title : "ID",
            field : "id",
            hidden : true
        }, {
            field : "pid",
            hidden : true
        },  {
            title : "AAA",
            field : "aaa",
            width : 70,
            align : "center",
            halign : "center"
        }, {
            title : "BBB",
            field : "bbb",
            width : 70,
            align : "center",
            halign : "center",
            editor : {
                type : "combobox",
                options : {
                    data : [ {
                        "id" : 0,
                        "text" : "苹果"
                    }, {
                        "id" : 1,
                        "text" : "梨子"
                    } ],
                    valueField : ‘id‘,
                    textField : ‘text‘,
                    editable : false,
                    // required : true,
                    panelHeight : "auto",
                    missingMessage : "请选择水果",
                    onSelect : function(record) {
                        //editingId是进入编辑状态行的id
                        var editors = $(‘#grid‘).datagrid(‘getEditors‘, $(‘#editingId‘).val());
                        if(record.id == 1){//选择梨子
                            var feditor = editors[1];//一行中第二个编辑框
                            //将编辑框设置成必填
                            $(feditor.target).validatebox({required:true});
                            //将编辑框设置成可编辑

                            $(feditor.target).numberbox(‘enable‘);
                            var feditor2 = editors[2];//一行中第三个编辑框
                            $(feditor2.target).validatebox({required:true});
                        }else if(record.id == 0){//选择苹果
                            var feditor = editors[1];
                            $(feditor.target).validatebox({required:false});
                            $(feditor.target).validatebox("setValue","");
                            $(feditor.target).numberbox(‘disable‘);
                            var feditor2 = editors[2];
                            $(feditor2.target).validatebox({required:false});
                            $(feditor2.target).validatebox("setValue","");
                        }
                    },
                }
            }
        }


开启编辑状态

$(‘#rulesgrid‘).treegrid(‘beginEdit‘, index);