jqgrid通过单独的Button将网格显示为子网格

时间:2010-01-19 10:57:16

标签: jquery jqgrid grid subgrid

我有一个问题是使用额外的按钮将网格显示为子网格。 我试图从

复制代码
subGridRowExpanded:

事件。 但是在触发subGridRowExpanded之前,Grid正在做一些令人讨厌的事情。 如果我使用左侧的+按钮,则网格显示正确。如果我现在按下我创建的按钮,也会重新加载subGrid。我使用警报在开始时停止该功能,我看到该表在subGridRowExpanded之前插入。

所以我想在事件发生之前我错过了一个函数。也许我正在为我的任务使用错误的事件。

这是我的代码,它来自基本示例。生成Button的函数:

gridComplete: function(){ 
    var ids = jQuery("#task").jqGrid('getDataIDs');
    var running_task_ids=get_running_task_id_ajax();
    for(var i=0;i < ids.length;i++){ 
        var cl = ids[i]; 
        start = "<input style='height:22px;width:50px;' type='button' value='Start' onclick=\"start_stop_task('"+cl+"','start');\" />"; 
        stop = "<input style='height:22px;width:50px;' type='button' value='Stop' onclick=\"start_stop_task('"+cl+"','stop');\" />";
        se = "<input style='height:22px;width:50px;' type='button' value='Save' onclick=\"jQuery('#task').saveRow('"+cl+"');\" />"; 
        //ce = "<input style='height:22px;width:20px;' type='button' value='C' onclick=\"jQuery('#task').restoreRow('"+cl+"');\" />"; 
        co = "<input style='height:22px;width:70px;' type='button' value='Comment' onclick=\"foobar('task_"+cl+"',"+cl+");\" />"; 
       }
}

调用的函数(仅作为子网格示例从Grid复制):

function foobar(subgrid_id, row_id) {
// klappt noch nicht!

alert(subgrid_id+":"+row_id);
// we pass two parameters 
// subgrid_id is a id of the div tag created whitin a table data 
// the id of this elemenet is a combination of the "sg_" + id of the row
 // the row_id is the id of the row 
 // If we wan to pass additinal parameters to the url we can use 
 // a method getRowData(row_id) - which returns associative array in type name-value 
 // here we can easy construct the flowing 
 var subgrid_table_id, pager_id;
  subgrid_table_id = subgrid_id+"_t";
  pager_id = "p_"+subgrid_table_id;
  $("#"+subgrid_id).html("<table id='"+subgrid_table_id+"' class='scroll'></table><div id='"+pager_id+"' class='scroll'></div>"); 
  jQuery("#"+subgrid_table_id).jqGrid({ 
      url:"ajax/listtasktime/id/"+row_id, 
      onSelectRow: 
          function(id){ 
            if(id && id!==lastsel2){ 
                    jQuery('#'+subgrid_table_id).jqGrid('restoreRow',lastsel2);  
                    //jQuery('#task').jqGrid('editRow',id,true,pickdates_e); 
                    jQuery('#'+subgrid_table_id).jqGrid('editRow',id,true); 
                    lastsel2=id; } 
      },

      datatype: "xml", 
      colNames: ['ID','START','END', 'Time'], 
      colModel: [ 
                 {name:"ID",index:"num",width:80,key:true}, 
                 {name:"START",index:"item",width:180,editable: true}, 
                 {name:"END",index:"qty",width:180,align:"right",editable: true},
                 {name:"TIME",index:"qty",width:180,align:"right"} 
                 ], 
                 rowNum:20, 
                 pager: pager_id, 
                 sortname: 'num', 
                 sortorder: "asc", 
                 height: '100%' 
                  }); 
  jQuery("#"+subgrid_table_id).jqGrid('navGrid',"#"+pager_id,{edit:false,add:false,del:false}) 
  alert("done");    
  }

1 个答案:

答案 0 :(得分:4)

我自己找到了。你不必调用一个单独的功能。由于jqGrid 3.3或类似的东西,有一个函数叫做:

toggleSubGridRow()

expandSubGridRow()

你可以这样调用这个函数:

<input type='button' value='Comment' onclick=\"jQuery('#list').toggleSubGridRow('"+rowid+"');\" />

如果点击了

中的注册功能
subGridRowExpanded: 
        function(subgrid_id, row_id) {...}

调用事件。

相关问题