jqGrid ondblClickRow无法正常工作

时间:2014-01-02 09:15:26

标签: php jquery codeigniter jqgrid

我是jqgrid的新手,我正在使用jqgrid与codeigniter一起显示数据。

这些是我的网格:

网格1

学生表

<table id="list"></table>
<div id="pager"></div>

grid 2

导师表

<table id="list1"></table>
<div id="pager1"></div>

当用户双击第一个网格的一行时,我正在加载第二个网格。

我的jqgrid代码是:

<script type="text/javascript">
    $(document).ready(function (){
        var lastSel;
        jQuery("#list").jqGrid({
            url:'<?php echo $base_url.'index.php/demo/loadData'?>',      //another controller function for generating data
            mtype : "post",             //Ajax request type. It also could be GET
            datatype: "json",            //supported formats XML, JSON or Arrray
            colNames:['Name','Email','Passport','Phone','Fax','Address','Note'],       //Grid column headings
            colModel:[
                {name:'name',index:'name', width:100, align:"left",editable:false},
                {name:'email',index:'email', width:150, align:"left",editable:false},
                {name:'passport',index:'passport', width:100, align:"right",editable:true},
                {name:'phone',index:'phone', width:100, align:"right",editable:false},
                {name:'fax',index:'fax', width:100, align:"right",editable:true},
                {name:'address',index:'address', width:100, align:"right",editable:true},
                {name:'note',index:'note',width:100,align:"right",editable:true},

                 ],
            rowNum:10,
            width: 750,
            //height: 300,
            rowList:[10,20,30],
            pager: '#pager',
            sortname: 'id',
            viewrecords: true,
            rownumbers: true,
            gridview: true,
            caption:"List Of Students",

            ondblClickRow:function(id){ 
                if(id && id!==lastSel){ 
                    jQuery('this').restoreRow(lastSel); 
                    lastSel=id; 
                 }  
            //   alert(id);
               jQuery("#list1").jqGrid({
                   url:"<?php echo $base_url.'index.php/demo/load_tutor_data/'?>"+$('#'+id).children("td[aria-describedby='list_passport']").html(),      //another controller function for generating data
                   mtype : "post",             //Ajax request type. It also could be GET
                   datatype: "json",            //supported formats XML, JSON or Arrray
                   colNames:['Name','Email','Passport','Phone','Fax','Address','Note','Assign',''],       //Grid column headings
                   colModel:[
                       {name:'name',index:'name', width:100, align:"left",editable:false},
                       {name:'email',index:'email', width:150, align:"left",editable:false},
                       {name:'passport',index:'passport', width:100, align:"right",editable:true},
                       {name:'phone',index:'phone', width:100, align:"right",editable:false},
                       {name:'fax',index:'fax', width:100, align:"right",editable:true},
                       {name:'address',index:'address', width:100, align:"right",editable:true},
                       {name:'note',index:'note',width:100,align:"right",editable:true},
                       {name: 'checkbox', index: 'checkbox', align:"center",editable: true,
                           edittype: 'checkbox', editoptions: { value: "True:False" ,defaultvalue:"False" }, 
                           formatter: "checkbox",  formatoptions: { disabled: false}  },
                           {name: 'myac', width:80, fixed:true, sortable:false, resize:false, formatter:'actions',
                            formatoptions:{keys:true}},

                       ],
                   rowNum:10,
                   width: 750,
                   //height: 300,
                   rowList:[10,20,30],
                   pager: '#pager1',
                   sortname: 'id',
                   viewrecords: true,
                   rownumbers: true,
                   gridview: true,
                   caption:"List Of Tutors",
                   onSelectRow:function(id){ 
                        alert("Assign Here");
                       },
                    onCellSelect:function(rowid, iCol, cellcontent, e){
                        if(iCol==8)
                        alert("make submit");
                       },    
                       editurl:"<?php echo $base_url.'index.php/demo/load_tutor_data'?>"

               }).navGrid('#pager1',{edit:false,add:false,del:false});
               $("#admintask").show();
               },
            editurl:"<?php echo $base_url.'index.php/demo/loadData'?>"

        }).navGrid('#pager',{edit:false,add:false,del:false});
        $("tr").click(function(){
            alert("test");

    });


    });
    $("#bsdata").click(function(){
        jQuery("#list").jqGrid('searchGrid',
            {sopt:['cn','bw','eq','ne','lt','gt','ew']}
        );
    });
    $("#bedata").click(function(){
        var gr = jQuery("#list").jqGrid('getGridParam','selrow');
        if( gr != null ) jQuery("#list").jqGrid('editGridRow',gr,     {height:280,reloadAfterSubmit:false});
        else alert("Please Select Row");
    });     
    $("#list").hover(function(){
        var gr = jQuery("#list").jqGrid('getGridParam','selrow');
    });
 $("#test1").click(function(){
     $("#admintask").hide();
 });
</script>

当我第一次双击学生表中的一行时,它可以正常工作。但是,当我双击学生表中的其他行时,它显示相同的数据。我检查了浏览器网络,它也没有向网络发布任何内容。

请让我知道我在哪里弄错了。

1 个答案:

答案 0 :(得分:1)

您必须在加载前卸载#list1网格,如下所示

$("#list1 ").jqGrid('GridUnload');
jQuery("#list1").jqGrid({ ...............});