2017-03-27 7 views
0

現在、私はAJAXではないデータテーブルを使用していますので、datasrcオプションを使用することはできません。印刷する前に列を整形する方法はありますか?関数や何かのように。あなたの助けが大変ありがとうございます。 (私は、例えば意味書式設定することで「constructionAmount」から値を取得し、$といくつかのコンマを追加する。)データテーブルのデータをフォーマットする

$("#showDepreciationMontlhytable").DataTable({    
      destroy:true, 
      responsive: true, 
      autoWidth : true, 
      searching: true, 
      data: transaction.transactionDetails,    
      columns:[ 
        {"data": "idRealEstate"}, 
        {"data": "name"}, 
        {"data": "addressState"}, 
        {"data": "depreciationDetail.constructionAmount"}, 
        {"data": "depreciationDetail.depreciationPercentageYearly"}, 
        {"data": "depreciationDetail.monthsUse"}, 
        {"data": "depreciationDetail.usefulLifeMonths"}, 
        {"data": "depreciationDetail.amount"} 
        ] ,  
      language: { 
       url: datatablesSpanishUrl 
      }, 
     });  

答えて

0

は答えを見つけ、あなたはそれがあるしかしダッタをフォーマットすることができますオプションを「レンダリング」があります必要です。

$("#showDepreciationMontlhytable").DataTable({    
      destroy:true, 
      responsive: true, 
      autoWidth : true, 
      searching: true, 
      data: transaction.transactionDetails, 
      columns:[ 
        {"data": "idRealEstate"}, 
        {"data": "name"}, 
        {"data": "addressState"}, 
        {"data": "depreciationDetail.constructionAmount", 
        "render" : function(data, type, full) 
         { 
          return currencyFormat(data,"$");       
         } 
        }, 
        {"data": "depreciationDetail.depreciationPercentageYearly"}, 
        {"data": "depreciationDetail.monthsUse"}, 
        {"data": "depreciationDetail.usefulLifeMonths"}, 
        {"data": "depreciationDetail.amount", 
        "render" : function(data, type, full) 
         { 
          return currencyFormat(data,"$");       
         } 
        } 
        ] ,  
      language: { 
       url: datatablesSpanishUrl 
      }, 
     }); 

function currencyFormat(n, currency) { 
return currency + " " + n.toFixed(decimalRounding).replace(/(\d)(?=(\d{3})+\.)/g, "$1,"); 

}

+1

まだ、それは私が合格したそれまでは2日、私自身の答えを受け入れることができないと言うことはできません。 – Omaruchan

関連する問題