使用美元符号和千位分隔符格式化 bootstrap table
Format a bootstrap table with dollar sign and thousand separator
我正在尝试格式化我的 bootstrap table,以便我可以读取 $12,000,000 而不是 12000000 + 它的页脚(汇总列)
我知道这可以插入一个 javascript 函数 +CSS。
感谢您的帮助。
这是我的 table.
的代码
<table id="exampleTableFromData" data-sort-order="desc" data-mobile-responsive="true" data-search="true" data-show-footer="true" data-footer-style="footerStyle">
<thead>
<tr>
<th data-field="Customers" data-sortable="true" data-align="left">Customer</th>
<th data-field="RM" data-sortable="true" data-align="right" data-footer-formatter="totalFormatter">Sales</th>
<th data-field="BO" data-sortable="true" data-align="right" data-footer-formatter="totalFormatter">Discount</th>
<th data-field="GGR" data-sortable="true" data-align="right" data-footer-formatter="totalFormatter">Net</th>
</tr>
</thead>
</table>
如果在 PHP
中,请尝试以下操作:
$num = 12000000;
echo '$' . number_format($num); // ,000,000
echo '$' . number_format($num, 2); // ,000,000.00
确定找到了使用此脚本为页脚设置正确格式的方法
function totalFormatter(data) {
var total = 0;
if (data.length > 0) {
var field = this.field;
total = data.reduce(function(sum, row) {
return sum + (+row[field]);
}, 0);
var num = '$' + total.toFixed(0).replace(/(\d)(?=(\d\d\d)+(?!\d))/g, ",");
return num;
}
return '';
};
我正在尝试格式化我的 bootstrap table,以便我可以读取 $12,000,000 而不是 12000000 + 它的页脚(汇总列) 我知道这可以插入一个 javascript 函数 +CSS。 感谢您的帮助。
这是我的 table.
的代码<table id="exampleTableFromData" data-sort-order="desc" data-mobile-responsive="true" data-search="true" data-show-footer="true" data-footer-style="footerStyle">
<thead>
<tr>
<th data-field="Customers" data-sortable="true" data-align="left">Customer</th>
<th data-field="RM" data-sortable="true" data-align="right" data-footer-formatter="totalFormatter">Sales</th>
<th data-field="BO" data-sortable="true" data-align="right" data-footer-formatter="totalFormatter">Discount</th>
<th data-field="GGR" data-sortable="true" data-align="right" data-footer-formatter="totalFormatter">Net</th>
</tr>
</thead>
</table>
如果在 PHP
中,请尝试以下操作:
$num = 12000000;
echo '$' . number_format($num); // ,000,000
echo '$' . number_format($num, 2); // ,000,000.00
确定找到了使用此脚本为页脚设置正确格式的方法
function totalFormatter(data) {
var total = 0;
if (data.length > 0) {
var field = this.field;
total = data.reduce(function(sum, row) {
return sum + (+row[field]);
}, 0);
var num = '$' + total.toFixed(0).replace(/(\d)(?=(\d\d\d)+(?!\d))/g, ",");
return num;
}
return '';
};