2013-09-10 137 views
6

我有我創建這樣的劍道網:格式Kendo Grid顯示美元符號並允許最多兩位小數?

function drawInvoiceTable() { 
    invoiceTable = $('#invoiceGrid').kendoGrid({ 
     sortable: true, 
     pageable: true, 
     dataSource: { 
      data: getData(), 
      pageSize: 10, 
      schema: { 
       model: { 
        id: 'test', 
        fields: { 
         active: false 
        } 
       } 
      } 
     }, 
     columns: [ 
      { template: "<input type='checkbox' id='chkInvoices' class='invoiceDisplay' name='chkInvoices' #= active ? checked='checked' : '' #/>", width: 30 }, 
      { field: 'accountNumber', title: 'Account', attributes: { 'class': 'accountnumber' }, sortable: true }, 
      { field: 'transactionDate', title: 'Trans Date', attributes: { 'class': 'transdate' }, width: 100, sortable: true }, 
      { field: 'TransType', title: 'Type', attributes: { 'class': 'transType' }, width: 60, sortable: true }, 
      { field: 'TransReferenceNumber', title: 'Reference Number', attributes: { 'class': 'refnumber' }, width: 135, sortable: true }, 
      { field: 'transactionDebitAmount', title: 'Amount', attributes: { 'class': 'amount' }, width: 90, sortable: true }, 
      { field: 'openBalance', title: 'Balance', width: 90, attributes: { 'class': 'balance' }, template: '#= kendo.format("{0:p}", openBalance) #', sortable: true }, 
      { field: 'discountAmount', title: 'Discount', format: "{0:c}", attributes: { 'class': 'discount', 'data-format': 'c' }, width: 90, sortable: false }, 
      { field: 'discountApplied', title: 'Discount Applied', width: 95, attributes: { 'class': 'discapplied' }, sortable: false }, 
      { field: 'paymentApplied', title: 'Payment Applied' , width: 95, attributes: { 'class': 'paymentapplied' }, sortable: false }, 
      { field: 'discountDate', title: 'Discount Date', attributes: { 'class': 'discountDate' } }, 
      { field: 'dueDate', title: 'Due Date', width: 90, sortable: true }    
     ] 
    }); 

    grid = $('#invoiceGrid').data('kendoGrid'); 
    dataSource = grid.dataSource; 
    data = dataSource.data(); 
} 

我怎麼能值在我的一些列的美元符號格式化,並允許最多2位小數,如$ 12541.23? 強大的文本

回答

21

在列定義使用format: "{0:c2}"

{ field:"price", title:"Price", format:"{0:c2}" }, 

c代表貨幣和2是小數

數量
+0

我嘗試了你上面的建議,但仍然沒有運氣。請看看我的jsfiddle [這裏](http://jsfiddle.net/JFy2C/6/) –

+7

你需要說該字段是'number'類型。在http://jsfiddle.net/JFy2C/8/上查看它對'discountAmount'(和其他字段)的修改。 – OnaBai

+0

這些格式字符串是否有任何文檔?找不到任何 –

0

你想設置column.format"{0:c2}" 「C2」是數字格式(貨幣,小數點後兩位),即defined here

+0

我嘗試了上面的建議,但仍然沒有運氣。請看我的jsfiddle [這裏](http://jsfiddle.net/JFy2C/6/) –