2012-04-15 88 views

回答

7

我試圖用prependTo而不是appendTo和所有的作品。到恰好我用

loadComplete: function() { 
    var iCol = getColumnIndexByName(grid, 'act'); 
    $(this).find(">tbody>tr.jqgrow>td:nth-child(" + (iCol + 1) + ")") 
     .each(function() { 
      $("<div>", { 
       title: "Custom", 
       mouseover: function() { 
        $(this).addClass('ui-state-hover'); 
       }, 
       mouseout: function() { 
        $(this).removeClass('ui-state-hover'); 
       }, 
       click: function(e) { 
        alert("'Custom' button is clicked in the rowis="+ 
         $(e.target).closest("tr.jqgrow").attr("id") +" !"); 
       } 
      } 
     ).css({"margin-right": "5px", float: "left", cursor: "pointer"}) 
      .addClass("ui-pg-div ui-inline-custom") 
      .append('<span class="ui-icon ui-icon-document"></span>') 
      .prependTo($(this).children("div")); 
    }); 
} 

相應demo顯示

enter image description here

我加入另外CSS

.ui-inline-custom.ui-state-hover span { margin: -1px; } 

爲懸停的小的改進對應這已經在實施the bug fix jqGrid 4.3.2。

更新:當前版本的free jqGrid支持簡單的方法來實現自定義按鈕。見the demo