gpt4 book ai didi

javascript - 如何计算 Bootstrap 表格列中的所有值并显示在表格页脚中

转载 作者:行者123 更新时间:2023-11-30 15:26:57 25 4
gpt4 key购买 nike

我有以下 Bootstrap Json 表。

Fiddle

我想在星号列和中添加所有值

 | Name               | Stars           | Forks             |

Total Stars $832 Total Forks $456

在表格中显示为“总星数”等

如何添加列并显示值?

<table id="table">
<thead>
<tr>
<th data-field="state" data-checkbox="true"></th>
<th data-field="name">Name</th>
<th data-field="stargazers_count">Stars</th>
<th data-field="forks_count">Forks</th>
</tr>
</thead>
</table>




JSON temp.json

{
"Name": "Julie own",
"Account": "C0010",
"LoanApproved": "12/5/2015",
"LastActivity": "4/1/2016",
"PledgedPortfolio": "1000000",
"MaxApprovedLoanAmt": "1000000",
"LoanBalance": "1849000",
"AvailableCredit": "201877.824375",
"Aging": "3",
"Brokerage": "My Broker",
"Contact": "R Johnson",
"ContactPhone": "-3614",
"RiskCategory": "Yellow",
"rows": [{
"Account": "086-1234",
"ClientName": "Sal Smith",
"AccountType": "Ret",
"LongMarketValue": "$450000"
}, {
"Account": "086-1235",
"ClientName": "y Smith",
"AccountType": "Trust",
"LongMarketValue": "$550000"
},
{
"Account": "086-1236",
"ClientName": "y Smith",
"AccountType": "Retail",
"LongMarketValue": "$550000"
}]
}

最佳答案

我不确定 bootstrap 表是否有任何计算总数的方法,但你可以手动计算并附加结果。

类似这样的东西

var data = [
{
"name": "bootstrap-table",
"stargazers_count": "526",
"forks_count": "122",
"description": "An extended Bootstrap table with radio, checkbox, sort, pagination, and other added features. (supports twitter bootstrap v2 and v3) "
},
{
"name": "multiple-select",
"stargazers_count": "288",
"forks_count": "150",
"description": "A jQuery plugin to select multiple elements with checkboxes :)"
},
{
"name": "bootstrap-show-password",
"stargazers_count": "32",
"forks_count": "11",
"description": "Show/hide password plugin for twitter bootstrap."
},
{
"name": "blog",
"stargazers_count": "13",
"forks_count": "4",
"description": "my blog"
},
{
"name": "scutech-redmine",
"stargazers_count": "6",
"forks_count": "3",
"description": "Redmine notification tools for chrome extension."
}
];

$(function () {
$('#table').bootstrapTable({
data: data
});
var totalStars = data.reduce(function(a, b){
return a + parseFloat(b.stargazers_count);
}, 0);
var totalForks = data.reduce(function(a, b){
return a + parseFloat(b.forks_count);
}, 0);
document.querySelector('.totalStars').innerHTML = totalStars;
document.querySelector('.totalForks').innerHTML = totalForks;
});
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<link rel="stylesheet" href="https://rawgit.com/wenzhixin/bootstrap-table/master/src/bootstrap-table.css">
</head>
<body>
<table id="table">
<thead>
<tr>
<th data-field="state" data-checkbox="true"></th>
<th data-field="name">Name</th>
<th data-field="stargazers_count">Stars</th>
<th data-field="forks_count">Forks</th>
</tr>
</thead>
<tfoot>
<tr>
<td></td>
<td></td>
<th>Total Stars <span class="totalStars"></span></th>
<th>Total Forks <span class="totalForks"></span></th>
</tr>
</tfoot>
</table>
<script src="https://code.jquery.com/jquery-3.1.0.js"></script>

<script src="https://rawgit.com/wenzhixin/bootstrap-table/master/src/bootstrap-table.js"></script>
</body>
</html>

关于javascript - 如何计算 Bootstrap 表格列中的所有值并显示在表格页脚中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42816168/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com