Потребовалось время, чтобы найти хорошее решение, и ваш formatNumber мне не помог;)
{
title: "Qty",
field: "qty",
formatter:"money", formatterParams:{ thousand:",", precision:false },
bottomCalc: function(values, data, calcParams) { if (values && values.length) {
var total = values.reduce((sum, x) => +sum + +x);
return (""+total).replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,");
}}, //"sum",
}
Я также добавил запятые ко всем ценам и qtys
Как это
$(document).ready(function() {
function formatNumber(num) {
return ("" + num).replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,");
}
function getSum(total, num) {
return total + num;
}
var adultCalc = function(values, data, calcParams) {
var totalcount = 0;
var count = 0;
var i = 0;
data.forEach(function(data) {
count = data.price * data.qty;
totalcount += count;
i++
});
return formatNumber(totalcount);
}
var tabledata = [{
id: 1,
name: "Item A",
price: "1000",
qty: "2000"
},
{
id: 3,
name: "Item B",
price: "8500",
qty: "1500"
},
{
id: 4,
name: "Item C",
price: "9100",
qty: "2500"
},
{
id: 5,
name: "Item D",
price: "950",
qty: "1100"
},
{
id: 5,
name: "Item E",
price: "2000",
qty: "750"
},
{
id: 4,
name: "Item F",
price: "2500",
qty: "1000"
}
];
var table = new Tabulator("#example-table", {
height: 205,
data: tabledata,
layout: "fitColumns",
columns: [{
title: "Name",
field: "name",
width: 150
},
{
title: "Price",
field: "price",
formatter: "money",
formatterParams: {
decimal: ".",
thousand: ",",
symbol: "$",
symbolAfter: "p",
precision: false,
},
bottomCalc: adultCalc
},
{
title: "Qty",
field: "qty",
formatter: "money",
formatterParams: {
thousand: ",",
precision: false
},
bottomCalc: function(values, data, calcParams) {
if (values && values.length) {
var total = values.reduce((sum, x) => +sum + +x);
return formatNumber(total)
}
}, //"sum",
}
]
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://unpkg.com/tabulator-tables@4.1.4/dist/css/tabulator.min.css" rel="stylesheet">
<script type="text/javascript" src="https://unpkg.com/tabulator-tables@4.1.4/dist/js/tabulator.min.js"></script>
<div id="example-table"></div>