Donate

Bootstrap Table Format Numbers With Comma And Decimal Places In ASP.NET MVC

Hello and Good Evening.
Here's how to format numbers with comma and decimal places in Bootstrap Table columns by Wenzhixin using data-formatter tag. Simple set the data-formatter property of the tag.
<table id="tblBilling"
	   data-toggle="table"
	   data-search="true"
	   data-advanced-search="true"
	   data-id-table="billingTable"
	   data-show-export="true"
	   data-toolbar="#toolbar1"
	   data-click-to-select="true"
	   data-height="500"
	   data-url='@Url.Action("GetBillingInformation", "BillingDashboard")'
	   data-cookie-id-table="tblBillableID">
	<thead>
		<tr style="background-color: #FFFFFF;">
			<td data-field="CustomerID" data-sortable="false" data-searchable="false" data-visible="false">Customer ID</td>
			<td data-field="CustomerName" data-sortable="false" data-searchable="false" data-visible="false">Customer Name</td>
			<th data-field="Address" data-sortable="true" data-searchable="true">Address</th>
			<th data-field="Price" data-sortable="true" data-formatter="NumFormatter" data-searchable="true">Price</th>
			<th data-field="TotalAmount" data-sortable="true" data-formatter="NumFormatter" data-searchable="true">Total Amount</th>
		</tr>
	</thead>
</table>
And the JavaScript code to format those numbers use only toLocaleString() function with parameters set for minimum and maximum fraction digits.
function NumFormatter (data) {
	return parseFloat(data).toLocaleString(undefined, {
		minimumFractionDigits: 2,
		maximumFractionDigits: 2
	});
};  
Output
Bootstrap Table Format Numbers With Comma And Decimal Places In ASP.NET MVC
Sample Fiddle: Bootstrap Table Format Numbers With Comma And Decimal Places

Comments

Donate

Popular Posts From This Blog

WPF CRUD Application Using DataGrid, MVVM Pattern, Entity Framework, And C#.NET

TypeScript Error Or Bug: The term 'tsc' is not recognized as the name of a cmdlet, function, script file, or operable program.

Invalid nested tag div found, expected closing tag input