我是先将下拉选项的值通过datagrid的url查出来了,在每一行的row中

//项目结果选项卡的列表
    $('#project_table').datagrid({
        width : '100%',
        height: '378',
        url : 'getSeparationProjectInf',
        //title : '待分发条码列表',
        striped : true,
        nowrap : true,
        rownumbers : true,
        singleSelect : true,
        showHeader : true,
        showFooter : false,
        loadMsg : '努力展开中...',
        scrollbarSize:0,
        fitColumns : true,
        checkOnSelect : true,
        onClickRow: function (rowIndex, rowData) {
            //$(this).datagrid('unselectRow', rowIndex);
            var _this = this;
            if (editIndex != undefined && editIndex != rowIndex) {
                //结束行编辑
                endEdit(_this,editIndex);
            }
            $(_this).datagrid('beginEdit', rowIndex);
            $("input.datagrid-editable-input").on("keypress",function(e){
                if(e.keyCode==13){
                    endEdit(_this,editIndex);
                }
            });
            editIndex = rowIndex;            
        },
        onBeginEdit: function(index, rowData){ //动态修改检测结果下拉项
            var resultDictionaryDetailList = rowData.resultDictionaryDetailList
            //监测结果下拉框  
            var goEditor = $('#project_table').datagrid('getEditor', {  
                      index : index,    
                       field : 'result'    
            });  
            $(goEditor.target).combobox({  
                onLoadSuccess: function () {
                    if(rowData.result){
                        $(goEditor.target).combobox('setValue', rowData.result);
                    }else{
                        $(goEditor.target).combobox('setValue', rowData.resultDictionaryDetailList[0].id);
                    }
                },
                onBeforeLoad: function(){   //下拉展开时动态修改options  
                    if(resultDictionaryDetailList.length){
                        var data = [];  
                        for ( var index in resultDictionaryDetailList) {
                            var resultDictionaryDetail = resultDictionaryDetailList[index];
                            data.push({'id': resultDictionaryDetail.id, 'name':resultDictionaryDetail.name});  
                        }
                        $(goEditor.target).combobox("loadData", data);  
                    }                 
                }  
            });  
        },
        columns : [[
            {
                field : 'ck',
                checkbox: true
            },
            {
                field : 'projectId',
                title : '项目ID',
                align : 'center',
                sortable : false,
                resizable : false,
                hidden: true
            },
            {
                field : 'projectName',
                title : '项目',
                align : 'center',
                sortable : false,
                resizable : false,
                width : 120                 
            },
            {
                field : 'data',
                title : '检测数据',
                align : 'center',
                sortable : false,
                resizable : false,
                width : 100,
                editor:{
                    type:'text'
                }                                                
            },            
            {
                field : 'result',
                title : '检测结果',
                align : 'center',
                sortable : false,
                resizable : false,
                width : 100,
                formatter: function (value, rowData, rowIndex) {
                    var resultDictionaryDetailList = rowData.resultDictionaryDetailList;
                    if(!value){
                        rowData.result = resultDictionaryDetailList[0].id;
                        value = resultDictionaryDetailList[0].name;
                    }
                    console.log("resultDictionaryDetailList.length=="+resultDictionaryDetailList.length);
                    for (var i = 0; i < resultDictionaryDetailList.length; i++) {  
                        if (resultDictionaryDetailList[i].id == value) {  
                            return resultDictionaryDetailList[i].name;  
                        }  
                    }  
                    return value;  
                },
                editor:{
                    type:'combobox',
                    options:{
                        valueField:'id',
                        textField:'name',
                        //method:'get',
                        //url:'products.json',
                        //data: resultDictionaryDetailList,
                        data: [{
                            productid: '0',
                            checkResult: '高'
                        },{
                            productid: '1',
                            checkResult: '低'
                        }],                     
                        required:true
                    }
                }
            },
            {
                field : 'remark',
                title : '结果备注',
                align : 'center',
                sortable : false,
                resizable : false,
                width : 120 ,
                editor : {type:"text"}               
            },
            {
                field : 'suggestion',
                title : '建议内容',
                align : 'center',
                sortable : false,
                resizable : false,
                width : 150,
                editor:{ type:'text' }
            },            
            {
                field : 'explanation',
                title : '医学解释',
                align : 'center',
                sortable : false,
                resizable : false,
                width : 150,
                editor:{ type:'text' }
            },
            {
                field : 'reason',
                title : '常见原因',
                align : 'center',
                sortable : false,
                resizable : false,
                width : 150,
                hidden: true
            },
            {
                field : 'operate',
                title : '操作',
                align : 'center',
                sortable : false,
                resizable : false,
                width : 80,
                formatter: function(value,row,index){
//                    return '<a href="javascript:void(0);" onclick="cancelDialog(event)">'+value+'</a>';
                }                
            }              
        ]],
        data : [
            /*{
                project : 'ERCC1基因表达',
                checkData : '≥3.4%',
                checkResult : '高',
                resultRemark : 'xxxxx',
                advise : '您患2型糖尿病的基因位.....',
                medicalExplanation : '合理安排休息,保证充分....',
                operate : '删除',                              
            }*/
        ],
        pagination : false,
        /*pageSize : 10,
        pageList : [10],
        pageNumber : 1,*/
        pagePosition : 'bottom',
        remoteSort : false,
    });

具体解析如下:

onBeginEdit是将row中的下拉项数据拿出来并动态加载到Combobox 中,onBeforeLoad很重要,不然执行onLoadSuccess方法的时候,Combobox还没有动态加载下拉选项,导致显示的是值,而不是值对应的名,所以用onBeforeLoad可以先加载Combobox的下拉选项,然后再回填值


onBeginEdit: function(index, rowData){ //动态修改检测结果下拉项
            var resultDictionaryDetailList = rowData.resultDictionaryDetailList
            //监测结果下拉框  
            var goEditor = $('#project_table').datagrid('getEditor', {  
                      index : index,    
                       field : 'result'    
            });  
            $(goEditor.target).combobox({  
                onLoadSuccess: function () {
                    if(rowData.result){
                        $(goEditor.target).combobox('setValue', rowData.result);
                    }else{
                        $(goEditor.target).combobox('setValue', rowData.resultDictionaryDetailList[0].id);
                    }
                },
                onBeforeLoad: function(){   //下拉展开时动态修改options  
                    //datatype处理统计方法  
                    if(resultDictionaryDetailList.length){
                        var data = [];  
                        for ( var index in resultDictionaryDetailList) {
                            var resultDictionaryDetail = resultDictionaryDetailList[index];
                            data.push({'id': resultDictionaryDetail.id, 'name':resultDictionaryDetail.name});  
                        }
                        $(goEditor.target).combobox("loadData", data);  
                    }  
                   /* //设置值                              
                    if(rowData.result){
                        $(goEditor.target).combobox('setValue', rowData.result);  
                    }else{
                        $(goEditor.target).combobox('setValue', rowData.resultDictionaryDetailList[0].name);
                    }*/                      
                }  
            });  
        },
 

formatter是将值转换成对应的name

formatter: function (value, rowData, rowIndex) { 
    var resultDictionaryDetailList = rowData.resultDictionaryDetailList;
    if(!value){
        value = resultDictionaryDetailList[0].id;
        rowData.result = value;
    }
    for (var i = 0; i < resultDictionaryDetailList.length; i++) {  
        if (resultDictionaryDetailList[i].id == value) {  
            return resultDictionaryDetailList[i].name;  
        }  
    }  
    return value;  
},

Easyui Datagrid 的Combobox 如何动态修改下拉选项,以及值的转换的更多相关文章

  1. jquery 动态添加下拉框 需要增加 煊染 selectmenu("refresh");

    若通过js动态选择下拉框的值必须刷新下拉框,例如:var selArray = $("select#sel");selArray[0].selectedIndex = 1;selA ...

  2. Easyui datagrid combobox输入框下拉(取消)选值和编辑已选值处理

    datagrid combobox输入框下拉(取消)选值和编辑已选值处理 by:授客 QQ:1033553122 测试环境 jquery-easyui-1.5.3   需求场景 如下,在datagri ...

  3. 通通WPF随笔(1)——基于lucene.NET让ComboBox拥有强大的下拉联想功能

    原文:通通WPF随笔(1)--基于lucene.NET让ComboBox拥有强大的下拉联想功能 我一直很疑惑百度.谷哥搜索框的下拉联想功能是怎么实现的?是不断地查询数据库吗?其实到现在我也不知道,他们 ...

  4. SupportV7包中 SwipeRefreshLayout 修改下拉控件的距离

    //修改下拉距离 ViewTreeObserver vto = mCategoryResults.mSwipeRefreshLayout.getViewTreeObserver(); vto.addO ...

  5. ComboBox 自动调整组合框下拉部分的宽度

    /// <summary>        /// ComboBox 自动调整组合框下拉部分的宽度        /// </summary>        void Resiz ...

  6. layui 根据根据后台数据动态创建下拉框并同时默认选中

        第一步 form表单里写好一个下拉框 <div class="layui-form-item"> <label class="layui-for ...

  7. Jquery动态设置下拉框selected --(2018 08/12-08/26周总结)

    1.Jquery动态根据内容设置下拉框selected 需求就是根据下拉框的值动态的设置为selected,本以为很简单,网上一大推的方法,挨着尝试了之后却发现没有一个是有用的.网上的做法如下: &l ...

  8. WPF-学习笔记 动态修改控件Margin的值

    原文:WPF-学习笔记 动态修改控件Margin的值 举例说明:动态添加一个TextBox到Grid中,并设置它的Margin: TextBox text = new TextBox(); t_gri ...

  9. jquery 根据后台传过来的值动态设置下拉框、单选框选中

    更多内容推荐微信公众号,欢迎关注: jquery  根据后台传过来的值动态设置下拉框.单选框选中 $(function(){ var sex=$("#sex").val(); va ...

随机推荐

  1. hiho1602本质不同的回文子串的数量

    给定一个字符串S,请统计S的所有子串中,有多少个本质不同的回文字符串? 注意如果两个位置不同的子串满足长度相同且对应字符也都相同,则认为这两个子串本质上是相同的. Input 一个只包含小写字母的字符 ...

  2. lua不支持的泛型方法

    1.没有泛型约束 2.缺少带约束的泛型参数 3.泛型约束必须为class /// <summary> /// 不支持生成lua的泛型方法(没有泛型约束) /// </summary& ...

  3. hadoop常见错误总结三

    问题导读:1.... could only be replicated to 0 nodes, instead of 1 ...可能的原因是什么?2.Error: java.lang.NullPoin ...

  4. {Reship}{Socket}C#简单应用

    This article come frome here ======================================================================= ...

  5. Oracle 之 配置HugePages内存

    HugePages是通过使用大页内存来取代传统的4kb内存页面,使得管理虚拟地址数变少,加快了从虚拟地址到物理地址的映射以及通过摒弃内存页面的换入换出以提高内存的整体性能.尤其是对于8GB以上的内存以 ...

  6. BZOJ3261:最大异或和

    浅谈\(Trie\):https://www.cnblogs.com/AKMer/p/10444829.html 题目传送门:https://lydsy.com/JudgeOnline/problem ...

  7. TCP/IP概念简述

    这里所说的是广义上的TCP/IP协议群,而不是特指TCP和IP这两种具体的协议.既然是协议群,那么都有哪些协议呢?我们先不着急回答这个问题,因为要弄清楚这个问题,首先得了解另两件事,就是为啥要有这个协 ...

  8. protobuf接口调用报错:java.nio.charset.MalformedInputException: Input length = 1

    使用protobuf定义的接口api发起http请求报错,日志如下: [-- ::] DEBUG AbstractPool: - server updated, node=, server={ nod ...

  9. vs2012加载T4MVC模板

    (1)在工程项目上右键点击“管理NuGet程序包”,在线搜索T4MVC模板,选择并安装,安装成功后,项目中会添加T4MVC.tt文件及子文件. (2)如果添加了新的控制器,则右击T4MVC.tt文件点 ...

  10. php分页类 可直接调用

    <?php /** * 分页类 * @author xyy * 调用分页实例 $subPages=new SubPages(数据总条数);//实例化分页类 * //$subPages->s ...