2013-09-10 15 views
6

Mam siatki kendo, że tworzenie tak:Format Kendo Grid, aby wyświetlić znak dolara i pozwolić maksymalnie dwa miejsca po przecinku?

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(); 
} 

Jak mogę mieć wartości w niektórych moich kolumn sformatowane ze znakiem dolara i pozwalają maksymalnie 2 przecinku, takich jak $ 12541.23? mocny tekst

Odpowiedz

21

W zastosowaniu definicji kolumny format: "{0:c2}":

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

c podpórek waluty i 2 jest liczba miejsc po przecinku

+0

Próbowałem tego, co sugerowałeś powyżej, ale wciąż nie było to szczęście. Proszę spojrzeć na moje jsfiddle [tutaj] (http://jsfiddle.net/JFy2C/6/) –

+7

Musisz powiedzieć, że pole jest typu 'liczba'. Zobacz tutaj http://jsfiddle.net/JFy2C/8/ dla 'discountAmount' (i innych pól) zmodyfikowanych. – OnaBai

+0

Czy istnieje dokumentacja dla tych ciągów formatów? Nie mogę znaleźć żadnego –

0

co chcesz ustawić column.format do "{0:c2}" "c2" jest formatem liczbowym (waluta, 2 miejsca po przecinku), który jest defined here.

+0

Próbowałem tego, co sugerowałeś powyżej, ale wciąż nie było szczęścia. Proszę spojrzeć na moje jsfiddle [tutaj] (http://jsfiddle.net/JFy2C/6/) –

Powiązane problemy