• Easyui里的datagrid嵌入select下拉框


    问题:
    想使用datagird里嵌入select下拉框,并在提交form表单时获取datagrid选中的每行数据里的每个下拉框选中的值。
    在这里插入图片描述
    解决方案:
    其中economicIssuesSelect使用下拉框,重点关注
    initEconomicIssues(row)方法。这里的方法需要传递row

             
            $('#queryPcpTable').datagrid({
                title: 'pcp领用查询信息',
                width: wd,
                url: send_url,
                queryParams:params,
                striped: true,
                pagination: true,
                pageNumber: 1,
                // 默认初始每页的行数
                pageSize: 5,
                // 每页行数可选列表
                pageList: [5],
                nowrap: true,
                checkOnSelect: true,
                selectOnCheck: true,
                columns: [[
                    {field: 'checkbox', checkbox: true},
                    {
                        field: 'consumingNo',
                        title: '领用单号',
                        align: 'center',
                        width: 180,
                        formatter:function(value,row,index) {
                            return ''+ value  + '';
                        }
                    },
                    {field: 'consumingNumber', title: '领用数量', align: 'center',
                        width: 120
                    },
                    {field: 'consumingAmount', title: '领用金额', align: 'center', width: wd * (1.3 / (col_size + 1))},
                    {field: 'economicIssuesSelect', title: '领用事项', align: 'center', width: wd * (1.3 / (col_size + 1)),
                        formatter:function(value,row,index) {
                            var selectHtml = initEconomicIssues(row);
                            return selectHtml;
                        }
                    },
                    // {   field: 'economicIssuesNo',
                    //     title: '领用事项', align: 'center',
                    //     width: wd * (1.3 / (col_size + 1)),
                    //     editor: {
                    //         type: 'combobox',//下拉框
                    //         options: {
                    //             valueField: 'economicIssuesNo',//对应为表格中的field
                    //             textField: 'economicIssuesDesc',//显示值
                    //             editable: false,
                    //             panelHeight:102,//控制下拉框高度
                    //             data: economicIssuesNoArryData,	//json数据
                    //             required: false
                    //         }
                    //     }
                    // },
                    {field: 'url', hidden:true }
                ]],
                onClickRow: function (rowIndex, rowData) {
                },
                onCheck: function (rowIndex, rowData) {
                },
                onUncheck: function (rowIndex, rowData) {
                },
                onLoadSuccess:function (data){
                    // var rows = $(this).datagrid("getRows");
                    // //使等级显示为下拉框
                    // for(var index=0;index
                    //     $(this).datagrid("beginEdit", index);
                    //     if($(this).datagrid("getEditor",{index:index,field:"economicIssuesNo"}).target.combobox('getValue') == ''){
                    //         $(this).datagrid("getEditor",{index:index,field:"economicIssuesNo"}).target.combobox('setValue', "空");
                    //     }
                    // }
                }
            });
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71

    其中economicIssuesNoArry是下拉框里list值,可以是写死也可以是动态ajax获取,这里的方法重点是select的id,这个id是拼凑出来的,由上个datagrid里的consumingNo(唯一主键)构成

     //初始化领用单号经济事项
        function initEconomicIssues(obj){
            if (economicIssuesNoArry.length > 0) {
                var html = '";
                return html;
            } else {
                //支出类别
                var issuesCategory = $("#issuesCategory").val();
                //支出项目
                var issuesClass = $("#issuesClass").val();
                //预算中心
                var budgetCenter = $('#budgetCenter').val();
                //机构代码
                var finBranchCode = $('#responsibleFinBranchCode').val();
    
                var html = "";
                //查询经济事项
                $.ajax({
                    type: 'post',
                    //     url: '${ctx}economicIssuesTbl/getEconomicIssuesNo.do?businessBook=${businessBook}&billType=${billType}' + '&issuesCategory=' + issuesCategory + '&issuesClass=' + issuesClass,
                    url: '${ctx}economicIssuesSet/getExpenseEconomicIssues.do?isExpensesApply=Y&businessBook=${businessBook}&billType=13&budgetCenter='
                        + budgetCenter + '&issuesCategory=' + issuesCategory
                        + '&finBranchCode=' + finBranchCode
                        + '&issuesClass=' + issuesClass,
                    dataType: 'json',
                    async: false,
                    success: function (result) {
                        var resData = result.rows;
                        for (var i = 0; i < resData.length; i++) {
                            if (resData[i].description.search("餐饮、茶歇") != -1) {
                                economicIssuesNoArry.push(resData[i]);
                            }
                            if (resData[i].description.search("杂费") != -1) {
                                economicIssuesNoArry.push(resData[i]);
                            }
                        }
                        html = '";
                    }
                });
                return html;
            }
    
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51

    获取datagird里的下拉框选中的value和text
    这里只需获取选中的rows数组然后通过下标获取对应的行数据,最后通过拼凑id值再使用
    $(“#id option:selected”).val();
    方法获取select选中的值和value

            var rows = $('#queryPcpTable').datagrid('getSelections');
            var num = rows.length;
            ......
          //已选中的领用单增加行
                    var rowObj = rows[i];
                    //获取领用事项的Id
                    var elementText = "#" +  "economicIssuesSelect" + rowObj.consumingNo + " option:selected";
                    //获取领用事项描述
                    var economicIssuesDesc = $(elementText).text();
                    //获取领用事项no
                    var economicIssuesNo =   $(elementText).val();
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
  • 相关阅读:
    腾讯云AI绘画:探究AI创意与技术的新边界
    MySQL数据库进阶第五篇(锁)
    使用MD5算法和sha512sum校验和检验文件完整性
    C_练习题 10
    Mysql Order单条记录出现在两页
    这么多年你还在怕正则吗?
    基于安卓android微信小程序的好物分享系统
    管理信息系统期末复习资料
    笔记--总线舵机YB-SD15M--stm32
    阿里云 压缩包 无法分享 解决方案
  • 原文地址:https://blog.csdn.net/weixin_41420919/article/details/132908534