2013-09-10 12 views
6

Ho un griglia kendo che creare in questo modo:Formatta la griglia Kendo per visualizzare il simbolo di dollari e consentire fino a due decimali?

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

Come posso avere dei valori in alcune delle mie colonne formattato con il simbolo del dollaro e consentire fino a 2 decimali come $ 12541,23? forte testo

risposta

21

Nell'uso definizione di colonna format: "{0:c2}":

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

c sta per valuta e 2 è il numero di decimali

+0

Ho provato quello che hai suggerito sopra, ma ancora senza fortuna. Per favore guarda il mio jsfiddle [qui] (http://jsfiddle.net/JFy2C/6/) –

+7

Devi dire che il campo è di tipo 'numero'. Guardalo qui http://jsfiddle.net/JFy2C/8/ per 'discountAmount' (e altri campi) modificato. – OnaBai

+0

C'è qualche documentazione per queste stringhe di formato? Non riesco a trovare nessuno –

0

Si consiglia di impostare il column.format-"{0:c2}" "c2" è il formato numerico (valuta, 2 posizioni decimali) che è defined here.

+0

Ho provato quello che hai suggerito sopra, ma ancora senza fortuna. Per favore guarda il mio jsfiddle [qui] (http://jsfiddle.net/JFy2C/6/) –

Problemi correlati