2009-09-06 39 views
4

我想处理jqgrid中的自定义按钮的点击。我有按钮显示,但当他们被点击时,我的功能不运行。如果我单击jqgrid外部的按钮,脚本就会运行。 jqgrid是否消耗按钮点击?不知道我失踪或不理解。这是网格。我没有重新加载整个网格的原因是服务器上的处理过多,并且一旦editurl处理“发送”,就需要手动删除客户端上的行。 See: $(".sendbuttons").click(function(){如何将脚本添加到jqgrid中的行上的自定义按钮?

...

 <style type="text/css"> 
     .sendbuttons { 
      height:19px; 
      width:60px; 
      color:red; 
     } 
    </style> 

    <script language="javascript"> 

    jQuery(document).ready(function(){ 
     var last_row; 
     jQuery("#gridlist").jqGrid({ 
      url:'manual_responses.php', 
      datatype: "json", 
      colNames:['ID','Image','Keyword','send Found','Proposed send',''], 
      colModel:[ 
       {name:'item_id', index:'item_id', width:45, editable:false, hidden:true}, 
       {name:'image', index:'image', width:45}, 
       {name:'keyword',index:'keyword', width:100, editable: false}, 
       {name:'item_found',index:'item_found', width:130, editable: false}, 
       {name:'proposed_send',index:'proposed_send', width:130, editable: true, edittype:"textarea", editoptions:{rows:"2",cols:"37"}}, 
       {name:'options',index:'options',width:40,editable: false} 
      ], 
      rowNum:40, 
      rowList:[20,40,60], 
      imgpath: 'css/themes/sand/images', 
      sortname: 'keyword', 
      viewrecords: true, 
      sortorder: "asc", 
      caption:"Proposed sends", 
      onSelectRow: function(item_id){ 
       if(item_id && item_id!==last_row){ 
        jQuery("#gridlist").restoreRow(last_row); 
        jQuery("#gridlist").editRow(item_id,true); 
        last_row=item_id; 
       } 
      }, 
      loadComplete: function(){ 
       //alert('ok, loadComplete running'); 
       var ids = jQuery("#gridlist").getDataIDs(); 
       for(var i=0;i<ids.length;i++){ 
        var cl = ids[i]; 
        send = "<input class='sendbuttons' id='tbuttonSend"+cl+"' type='button' value='Send' /><br />"; 
        clear = "<input class='sendbuttons' id='tbuttonClear"+cl+"' type='button' value='Send' /><br />"; 
        jQuery("#gridlist").setRowData(ids[i],{options:send+clear}) 
       } 
      }, 
      editurl: "item_send.php", 
      height:400, 
      width:796, 
      reloadAfterSubmit:false 
     }).navGrid('#pager2',{edit:true,add:false,del:false }); 

     $(".sendbuttons").click(function(){ 
      alert("got to 1"); 
     }); 
    }); 

    </script> 
</head> 
<body> 

    <table id="gridlist" class="scroll" cellpadding="0" cellspacing="0"></table> 
    <div id="pager2" class="scroll" style="text-align:center;"></div> 

    <input type='button' class='sendbuttons' id='323423x' value='go:'/> 

</body> 
</html> 
+0

我正在努力自己回答这个问题,我想我正朝着正确的方向前进。我修改了我的按钮点击事件来调用saveRow函数,并传递了succesfunc函数和url。不幸的是,这个网址似乎被误解了......在Firebug控制台里它说item_send没有定义。网址应该是什么样的限制?我的网址是item_send.php。 send =“
”; – dwaz 2009-09-09 12:42:33

回答

5

很明显,单击事件,

$(".sendbuttons").click(function(){ 
    alert("got to 1"); 
}); 

永远不会触发,因为该行的点击消耗它。但是,您可以在按钮中放入自己的onclick代码。

send = "<input name='send' class='tweetbuttons' id='tbuttonSend"+cl+ 
     "' type='button' value='Send' 
     onclick=jQuery('#list2').saveRow("+cl+",function(){alert('made it here')},item_send); /><br />"; 

正如我的评论所述,我可以用任何参数调用saveRow函数。

0

添加

$(".sendbuttons").click(function(){ 
    alert("got to 1"); 
}); 

在gridComplete回调和它触发。

loadComplete: function(){ 
    //alert('ok, loadComplete running'); 
    var ids = jQuery("#gridlist").getDataIDs(); 
    for(var i=0;i<ids.length;i++){ 
     var cl = ids[i]; 
     send = "<input class='sendbuttons' id='tbuttonSend"+cl+"' type='button' value='Send' /><br />"; 
     clear = "<input class='sendbuttons' id='tbuttonClear"+cl+"' type='button' value='Send' /><br />"; 
     jQuery("#gridlist").setRowData(ids[i],{options:send+clear}) 
} 
    $(".sendbuttons").click(function(){ 
     alert("got to 1"); 
    }); 
}, 
相关问题