gpt4 book ai didi

javascript - 如何获取包含每行值总和的总列

转载 作者:行者123 更新时间:2023-11-28 03:37:04 25 4
gpt4 key购买 nike

我已经从 MySQL 数据库生成了 laravel YajraBox 数据表。它工作得很好,但现在我想添加一个总列,其中包含每行值的总和。

见下文:

tableview

<script>
$(document).ready(function(){

$('#jobsTable').DataTable({
processing: true,
serverSide: true,
ajax: "{{ route('jobs.get') }}",

columnDefs: [
{ targets: [0,3,9,10,11,12,13,14,15,16], orderable: false },
{ targets: [0,3,9,10,11,12,13,14,15,16], searchable:false },
{ targets: [0,9,10,11,12,13,14,15,16,17,18,19], defaultContent: "" },
],

columns:[
/* 0 */ {data: 'action', name:'action'},
/* 1 */ {data: 'job_no', name: 'job_no'},
/* 2 */ {data: 'deal_no', name: 'deal_no'},
/* 3 */ {data: 'cyc_no', name: 'cyc_no'},
/* 4 */ {data: 'deal_name', name: 'deal_name'},
/* 5 */ {data: 'site', name: 'site'},
/* 6 */ {data: 'market_cat', name: 'market_cat'},
/* 7 */ {data: 'style', name: 'style'},
/* 8 */ {data: 'main_rend', name: 'main_rend'},
/* 9 */ {data: 'typwp_pges', name: 'typwp_pges'},
/* 10 */ {data: 'typalts_pges', name: 'typalts_pges'},
/* 11 */ {data: 'eowp_pges', name: 'eowp_pges'},
/* 12 */ {data: 'eoalts', name: 'eoalts'},
/* 13 */ {data: 'frshtyp_pges', name: 'frshtyp_pges'},
/* 14 */ {data: 'pdf_pges', name: 'pdf_pges'},
/* 15 */ {data: 'spin_pges', name: 'spin_pges'},
/* 16 */ {data: 'qc_pges', name: 'qc_pges'},
/* 17 */ {data: 'assigned', name: 'assigned'},
/* 18 */ {data: 'team', name: 'team'},
/* 19 */ {data: 'due_out', name: 'due_out'},
],
rowGroup: {
dataSrc: 'due_out'
}

});



});

</script>

我要添加典型wp_pges+typalts_pges+eowp_pges+eoalts+frshtyp_pges+pdf_pges+spin_pges+qc_pges

最佳答案

您可以使用columns.render选项,就像这样:

//data source
const srcData = [
{'item': 'itemA', '2017': 7, '2018': 5, '2019': 4},
{'item': 'itemB', '2017': 6, '2018': 3, '2019': 3},
{'item': 'itemC', '2017': 9, '2018': 8, '2019': 5}
];

//datatable initialization
$('table').DataTable({
dom: 't',
data: srcData,
columns: [
{title: 'item', data: 'item'},
{title: '2017', data: '2017'},
{title: '2018', data: '2018'},
{title: '2019', data: '2019'},
{title: 'sum', data: null, render: (_,__,rowData) => /*list summarized properties to make code a bit more compact*/['2017','2018','2019'].reduce((sum, prop) => sum+Number(rowData[prop]),0)}
]
});
<!doctype html><html><head><link rel="stylesheet"type="text/css"href="https://cdn.datatables.net/v/dt/jq-3.3.1/dt-1.10.18/rg-1.1.0/datatables.min.css"/><script type="application/javascript"src="https://code.jquery.com/jquery-3.3.1.min.js"></script><script type="text/javascript"src="https://cdn.datatables.net/v/dt/jq-3.3.1/dt-1.10.18/rg-1.1.0/datatables.min.js"></script></head><body><table></table></body></html>

关于javascript - 如何获取包含每行值总和的总列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57625110/

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