我是先将下拉选项的值通过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. 拷贝ssh公钥到多台服务器上

    这篇文章几乎是对Push SSH public keys to multiple host的翻译,谢谢该作者. 使用SSH登陆.执行命令到远程机器需要输入密码,很多系统需要免输密码访问远程机器,比如h ...

  2. tab页面自动跳转原因【在控制ul和li的时候没有细分】

    效果图 存储buy的tab跳转js代码 $(function() { $('.tabPanel ul li').click(function(){ $(this).addClass('hit').si ...

  3. PHP获取客户端的IP、地理信息、浏览器、本地真实IP

    <?php header("Content-type:text/html;charset=utf-8"); // 作用获取客户端的ip.地理信息.浏览器.本地真实IP cla ...

  4. 定义文档兼容性、让IE按指定版本解析我们的页面

    http://blog.useasp.net/archive/2013/05/29/x-UA-compatible-defining-document-compatibility-emulate-ie ...

  5. c++ hook 钩子的使用介绍

    转自:http://www.cnblogs.com/lidabo/archive/2012/11/29/2795269.html 例子:http://www.codeproject.com/Artic ...

  6. 【DUBBO】dobbo的application的配置项

    Dubbo:application的配置项[一]:配置项 <dubbo:application name="服务名字" owner="拥有者" organ ...

  7. windows环境vagrant修改静态资源文件,centos虚拟机中nginx的web环境下不生效

    最近上手krpano,本地修改了krpano.html文件或者xml文件,在虚拟机环境打开文件是修改过来了,在nginx中就是不生效. 修改nginx.conf中http{}中的 sendfile  ...

  8. 记一次socket_create()函数耗时异常记录

    背景: 下午开发时突然整个页面耗时增加,空接口每次都需要2-3秒的耗时,一开始以为连开发环境数据库出现问题,最后断开数据库跑,发现还是很慢 最终逐步调试此页面耗时,定位到了socket_create( ...

  9. emacs之配置etags-select

    etags-select比自带的etags定位的更好 ~/emacsConfig/etags-select-setting.el (require 'etags-select) (global-set ...

  10. Java 打印一个心心

    package Day8_06; public class For { public static void main(String[] args) { System.out.println(&quo ...