I tried to make a callout to SAP webservice through Javascript Remoting and writing the response to the visualforce page DOM using the same javascript. Now, i have an issue that the amount field which i am writing to DOM ignored the formatting option for that. Any suggestions please.
I am writing "GrandTotal" to this apex tag and it ignores to apply the currency format.
<apex:outputText id="GrandTotal" value="{0,number,currency}">
<apex:param value="{!InvTotalAmount}" />
</apex:outputText>
and the output is just a plain without $ currency symbol and thousand separator.
2537789.35
Visualforce page code snippet:
<apex:pageBlock id="OpenInvoices" title="Open Invoices" rendered="{!displayOpenInvoices}" >
<div id="invTable" style="display:none">
<table width="100%">
<tr>
<td width="15%"><b>Number of Open Invoices:</b></td>
<td id="textInvNumOf" width="5%" align="left">{!InvNumOf}</td>
<td width="8%"><b>Total Amount:</b></td>
<td width="15%" align="left">
<apex:outputText id="GrandTotal" value="{0,number,currency}">
<apex:param value="{!InvTotalAmount}" />
</apex:outputText>
and the javascript remoting script is given below.
</apex:pageBlock>
</div>
</apex:form>
<script type="text/javascript">
function getRemoteInvoicesData(CustNo) {
Visualforce.remoting.Manager.invokeAction(
'{!$RemoteAction.NewOpenDocumentsController.TestOpenInvoices}',
CustNo,
function(result, event){
//alert(result);
//alert(event.status);
if (event.status) {
// Get DOM IDs for HTML and Visualforce elements like this
var strHeader = '<table id="example" class="dataTable" cellspacing="0" width="100%">';
strHeader +='<thead><tr><th>Invoice Number</th><th>Invoice Date</th><th>Payer</th><th>Payer Name</th><th>Amount</th><th>Currency</th><th>Payment Due Date</th><th>Overdue Days</th></tr></thead>';
var strRowData = '<tbody>';
var strFullData = '';
var GrandAmt = 0.0;
//alert(result.length);
var i = 0;
for (; i < result.length; i++) {
strRowData += '<tr><td>'+result[0,i].InvoiceNumber+'</td>';
strRowData += '<td>'+result[1,i].InvoiceDateCSV+'</td>';
strRowData += '<td>'+result[2,i].Payer+'</td>';
strRowData += '<td>'+result[3,i].PayerName+'</td>';
strRowData += '<td>'+result[4,i].Amount+'</td>';
GrandAmt += result[4,i].Amount;
strRowData += '<td>'+result[5,i].Curren+'</td>';
strRowData += '<td>'+result[6,i].PaymentDueDateCSV+'</td>';
strRowData += '<td>'+result[7,i].NoDueDays+'</td></tr>';
}
strFullData = strHeader+strRowData+'</tbody></thead></table>';
j$('#loading-image').hide();
j$('#invTable').show();
document.getElementById('{!$Component.myForm.OpenInvoices.GrandTotal}').innerHTML = '$'+GrandAmt.toFixed(2);
document.getElementById('textInvNumOf').innerHTML = i;
document.getElementById('AllOpenInv').innerHTML = strFullData;
j$('#example').dataTable({
sPaginationType: "full_numbers"
});
} else if (event.type === 'exception') {
document.getElementById("AllOpenInv").innerHTML =
event.message + "<br/>\n<pre>" + event.where + "</pre>";
j$('#loading-image').hide();
} else {
document.getElementById("AllOpenInv").innerHTML = event.message;
j$('#loading-image').hide();
}
},
{escape: false, timeout: 120000}
);
return true;
}
$(document).ready(function() {
var j$ = jQuery.noConflict();
j$('#example').dataTable({
sPaginationType: "full_numbers"
});
});
</script>
</body>
</apex:page>