1

追加のボタンを使用してグリッドをサブグリッドとして表示する際に問題があります。からコードをコピーしようとしました

subGridRowExpanded:

イベント。しかし、subGridRowExpanded が起動される前に、Grid は厄介なことをしています。左側の + ボタンを使用すると、グリッドが正しく表示されます。作成したボタンを押すと、サブグリッドもリロードされます。最初にアラートを使用して関数を停止したところ、subGridRowExpanded の前にテーブルが挿入されていることがわかりました。

したがって、イベントの前に関数が欠落していると思います。タスクに間違ったイベントを使用している可能性があります。

基本的な例からの私のコードは次のとおりです。ボタンを生成する関数:

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+");\" />"; 
       }
}

呼び出される関数 (サブグリッドの例としてグリッドからコピーされたもの):

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");    
  }
4

1 に答える 1

4

私はそれを自分で見つけました。別の関数を呼び出す必要はありません。jqGrid 3.3以降、次のような関数があります。

toggleSubGridRow()

また

expandSubGridRow()

次のように関数を呼び出すことができます。

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

から登録した機能をクリックすると、

subGridRowExpanded: 
        function(subgrid_id, row_id) {...}

イベントが呼び出されます。

于 2010-01-19T21:33:07.987 に答える