2011-05-13 53 views
14

我有一個jqGrid的,其選擇:formatter => "currency"jqGrid的貨幣格式

它轉換數5$5.00,但是這是一個信用額度,所以我需要顯示爲($5.00),而不是$5.00

任何建議我應該在:formatter => "currency"中更改哪些內容?

回答

22

您應該檢查the currency formatter的選項。您可以定義prefixsuffix。例如,您可以在您需要的表單中使用下列選項

formatter:'currency', 
formatoptions: {prefix:'($', suffix:')', thousandsSeparator:','} 

The demo顯示在「合計」列中的數字。

enter image description here

+0

它表明我$ 5.00我需要($ 5.00),而不是$ 5.00此列下面的代碼:

 <%= jqgrid(" ", "registration_transactions_grid", "/registration_transactions/grid_data/#{grid_data_key}/#{grid_data_id}", \t [ { :field => "id", :hidden => true }, { :field => "amount", :label => "Amount", :width => 50, :name => "amount", :index => "amount", :align => "right", :formatter => "currency" } \t ] %> 
2011-05-13 16:15:55

+0

阿德南汗:你寫 「它告訴我$ 5.00」。 **什麼**顯示你? [我的演示](http://www.ok-soft-gmbh.com/jqGrid/SimpleLocalGridCurrency.htm)顯示($ 5.00)而不是$ 5.00。我不明白你使用的語法。 jqGrid是用** JavaScript **編寫的。它使用了一些預格式化器,您需要在前面描述的前綴和後綴湖中添加'formatoptions'。我無法在您發佈的代碼中找到該代碼,因此您不會在貨幣值上使用括號。 – Oleg 2011-05-13 16:36:47

+0

@ Oleg,我也需要使用貨幣格式化程序。但在我的情況下,我需要檢查一個條件。如果金額是** + ve **需要顯示** $ 180.00 **。如果金額爲** - ve **,則需要顯示爲**($ 180.00)**。你能提出任何想法嗎? – vissu 2012-05-04 09:29:05