开发者社区> 问答> 正文

怎么在easyui的datagrid里面设计级联下拉列表

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>test</title>
 
<script type="text/javascript">
    $(function(){
        var lastIndex;
    $('#tt').datagrid({
        url: 'dategrid_data.json',
        rownumbers: true,
        collapsible:true,
        striped: true,
        columns:[[
                {field:'id',title:'id',hidden:true},
                {field:'type',title:'类型',width:150,align:'center',
                    editor:{type:'combobox',options:{required:true}}
                },
                {field:'name',title:'名称',width:150, align:'center',
                    editor:{type:'combobox',options:{required:true}}
                },
            ]],
        toolbar:[
            {   
                text:'增加',      
                iconCls:'icon-add',
                handler:function(){
                $('#tt').datagrid('endEdit', lastIndex);
            $('#tt').datagrid('appendRow',{
                    id:'',
                type:'',
                name:''
            });
            var lastIndex = $('#tt').datagrid('getRows').length-1;
            }
        },'-',{
            text:'删除',
            iconCls:'icon-remove',
            handler:function(){
            var row = $('#tt').datagrid('getSelected');
            if (row){
                var index = $('#tt').datagrid('getRowIndex', row);
                $('#tt').datagrid('deleteRow', index);
            }
            }
        }
        ],
        onBeforeLoad:function(){
        $(this).datagrid('rejectChanges');
        }
    });
     
</script>
</head>
<body >
    <table align="center" id="tt" style="height:auto" width="100%" title="test" singleSelect="true" >
    </table>              
</body>
</html>
页面的大致代码如上,使用的版本是jquery-easyui-1.2.3,我想把datagrid中的type和name这两列做成级联下拉列表,但是我不知道怎么在点击下拉列表后获取到这个下拉列表所在行的rowIndex,还请各位指点!

展开
收起
a123456678 2016-07-07 15:52:50 3346 0
1 条回答
写回答
取消 提交回答
  • function getRowIndex(target) { 
        var tr = $(target).closest('tr.datagrid-row'); 
        return parseInt(tr.attr('datagrid-row-index')); 
    } 

    然后用getRowIndex(this)

    2019-07-17 19:52:54
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载