码迷,mamicode.com
首页 > 其他好文 > 详细

Easyui Datagrid 的Combobox 如何动态修改下拉选项,以及值的转换

时间:2017-09-17 17:26:26      阅读:755      评论:0      收藏:0      [点我收藏+]

标签:code   糖尿病   push   sep   keycode   selectrow   操作   box   ==   

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

    //项目结果选项卡的列表
    $(‘#project_table‘).datagrid({
        width : ‘100%‘,
        height: ‘378‘,
        url : ‘getSeparationProjectInf‘,
        //title : ‘待分发条码列表‘,
        striped : true,
        nowrap : true,
        rownumbers : true,
        singleSelect : false,
        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
            console.log(resultDictionaryDetailList);
            //监测结果下拉框  
            var goEditor = $(‘#project_table‘).datagrid(‘getEditor‘, {  
                      index : index,    
                       field : ‘result‘    
            });  
            $(goEditor.target).combobox({  
                onLoadSuccess: function () {  
                     $(goEditor.target).combobox(‘setValue‘, rowData.resultDictionaryDetailList[0].id);  
                },  
                onShowPanel: 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);  
                    }  
                    //设置值                              
                    $(goEditor.target).combobox(‘setValue‘, rowData.resultDictionaryDetailList[0].id);                      
                }  
            });  
        },
        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){
                        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;  
                },
                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 中

onBeginEdit: function(index, rowData){ //动态修改检测结果下拉项
            var resultDictionaryDetailList = rowData.resultDictionaryDetailList
            console.log(resultDictionaryDetailList);
            //监测结果下拉框  
            var goEditor = $(‘#project_table‘).datagrid(‘getEditor‘, {  
                      index : index,    
                       field : ‘result‘    
            });  
            $(goEditor.target).combobox({  
                onLoadSuccess: function () {  
                     $(goEditor.target).combobox(‘setValue‘, rowData.resultDictionaryDetailList[0].id);  
                },  
                onShowPanel: 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);  
                    }  
                    //设置值                              
                    $(goEditor.target).combobox(‘setValue‘, rowData.resultDictionaryDetailList[0].id);                      
                }  
            });  
        },

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 如何动态修改下拉选项,以及值的转换

标签:code   糖尿病   push   sep   keycode   selectrow   操作   box   ==   

原文地址:http://www.cnblogs.com/OnlyCT/p/7536116.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!