在Grid中增加下拉框

2 篇文章 0 订阅
2 篇文章 0 订阅
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link href="../../lib/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
    <script src="../../lib/jquery/jquery-1.9.0.min.js" type="text/javascript"></script>
    <script src="../../lib/ligerUI/js/core/base.js" type="text/javascript"></script>
    <script src="../../lib/ligerUI/js/plugins/ligerGrid.js" type="text/javascript"></script>
        <script src="../../lib/ligerUI/js/plugins/ligerResizable.js" type="text/javascript"></script>
    <script src="../../lib/ligerUI/js/plugins/ligerCheckBox.js" type="text/javascript"></script>
    
    
    <script type="text/javascript">
        //可以编辑的列
            var roleStr = "PMA";
            //下拉框选项
            var comboList = ["未处理", "处理中", "已处理", "其他"];               
            
        $(function ()
        {
            var jsonObj = {};
            jsonObj.Rows = [
                { id: 3, name: "林三", sex: "男", birthday: "1989/01/12", PMA:"未处理", PMB: "未处理", PMC: "未处理" },
                { id: 43, name: "陈丽", sex: "女", birthday: "1989/01/12", PMA:"未处理", PMB: "未处理", PMC: "未处理" },
                { id: 33, name: "啊三", sex: "男", birthday: "1981/12/12", PMA:"处理中", PMB: "未处理", PMC: "未处理" },
                { id: 34, name: "表三", sex: "男", birthday: "1983/01/12", PMA:"未处理", PMB: "已处理", PMC: "未处理" },
                { id: 43, name: "陈丽", sex: "女", birthday: "1989/01/12", PMA:"未处理", PMB: "未处理", PMC: "未处理" },
                { id: 33, name: "成三", sex: "男", birthday: "1989/11/23", PMA:"未处理", PMB: "未处理", PMC: "未处理" },
                { id: 34, name: "都三", sex: "女", birthday: "1989/04/12", PMA:"未处理", PMB: "未处理", PMC: "未处理" },
                { id: 324, name: "鄂三", sex: "男", birthday: "1999/05/15", PMA:"未处理", PMB: "未处理", PMC: "不需要" },
                { id: 344, name: "林三", sex: "男", birthday: "1969/02/21", PMA:"未处理", PMB: "未处理", PMC: "未处理" },
                { id: 1, name: "王开", sex: "男", birthday: "1989/01/12", PMA:"未处理", PMB: "不知道", PMC: "未处理" }
            ];
            
        
                        
            $("#maingrid").ligerGrid({
                columns: [                
                { display: '主键', name: 'id', width: 50, type: 'int' },
                { display: '名字', name: 'name', width: 50 },
                { display: '性别', name: 'sex', width: 50, isSort: false
               },  
               {
                    display: 'PMA', isAllowHide: false,
                    render: function (row)
                    {    
                        return createSelect('PMA', row.id, row.PMA);
                    }
               },
               {
                    display: 'PMB', isAllowHide: false,
                    render: function (row)
                    {    
                        return createSelect('PMB', row.id, row.PMB);
                    }
               },
                {
                    display: 'PMC', isAllowHide: false,
                    render: function (row)
                    {    
                        return createSelect('PMC', row.id, row.PMC);
                    }
                }
                
                ],width:'100%',
                data: jsonObj, 
                pageSizeOptions: [5, 10, 15, 20] 
            });
        });
        
        //绑定下拉框
        function createSelect(stype, id, val){
       
        //可以操作
        if(stype == roleStr){
        var html = '<select id="pid_' + id + '" οnchange="gradeChange(' + id + ')">';
       
        $.each(comboList,function(index,value){
if(val == value || ($.inArray(val, comboList)== -1 && value == "其他" ))
html += '<option value="'+ value +'" selected="selected">'+ value + '</a>';
else
html += '<option value="'+ value +'">'+ value + '</a>';
});
                        
        html += "</select>";
        }
        else{
        html = val;
        }
        return html;
        }
        
// 选中后的事件
        function gradeChange(id){   
        var opt=$("#pid_" + id).val();
        var options=$("#pid_" + id + " option:selected");
       
        alert("您选中SELECT的ID是" + id + "  值:" + options.val());
        }


    </script>
</head>
<body>
    <div id="maingrid"></div>   
</div>
</body>

</html>


如果有不清楚可以联系作者:bertchen   微信号:bertchen1206

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值