2012-07-23 92 views
1
var jqGridModel = [ 
      { name: 'month', index: 'Month', width: 120, sorttype: "String", hidden: true }, //hidden column 
      {name: 'monthID', index: 'MonthID', width: 120, sorttype: "int", formatter: convertToMonthName }, 
      { name: 'amount', type: "Decimal", index: 'amount', width: 120, sorttype: "float", formatter: 'currency', formatoptions: { decimalSeparator: fmtr[0], thousandsSeparator: fmtr[1], decimalPlaces: 2, suffix: fmtr[3], prefix: fmtr[2]} }, 
      ]; 

fmtr是我定義的用於處理多種貨幣的自定義方法。jqgrid:將圖標添加到預定義的格式列中

在上面的網格中,我希望在金額值旁邊的金額列中有圖片。點擊這個圖片後,它會帶你到另一個頁面,顯示金額的細節(分解)。

由於我已經使用'貨幣'格式化程序,我不確定是否可以在該列上使用自定義格式化程序。有什麼選擇來實現這一點。

我以爲圖像添加到後綴是這樣的:

// suffix: fmtr[3] + "<img src='../Content/img/show-detail-icon.png'/> onclick='showDetails'" 

但在這種情況下,我不知道如何monthID傳遞到的onclick功能。

回答

1

您可以從自定義格式化函數調用currency格式化程序 - 有關示例,請參閱this answer。使用格式化程序的好處在於,您可以訪問單元格值以及行對象(對於同一行中的其他單元格值)。這樣你就可以將你需要的任何ID傳給onclick處理程序。

+0

是啊,我以前不知道。這似乎很好。 – sam113 2012-07-26 10:37:08