I want to make a table to be able to help me make price comparisons. Explanations: In my table I have:
Project
Product
Manufacturer
Title
Quantity
Unit buying price (sum)
Total price buying (sum)
Multiply (average)
Unit sales price (sum)
Total sales price (sum)
Profit (sum)
The ideal in my case would be to select the lines I want to keep to see the total price of my choices. So I can see the cost of different options.
someone would have an idea or have already encountered this problem?
Thank you for helps :)
EDIT the sum for each columns work fine, but when i don't find how to have only the sum for each columns when i select them. Sorry but i am not comfortable with js :-/
// Remove the formatting to get integer data for summation
var intVal = function ( i ) {
return typeof i === 'string' ?
i.replace(/[\$,]/g, '')*1 :
typeof i === 'number' ?
i : 0;
};
$(document).ready(function() {
var table = $('#example').DataTable( {
columnDefs: [{
targets: [4,5,6,8,9,10],
render: $.fn.dataTable.render.number(',', '.', 2)
}],
responsive: true,
paging:false,
"footerCallback": function ( row, data, start, end, display ) {
var api = this.api(), data;
var sumColumns = [4,5,6,8,9,10];
sumColumns.forEach(function(colIndex){
// Total over all pages
var total = api
.rows({ selected: true })
.column(colIndex)
.data()
.reduce( function (a, b) {
return intVal(a) + intVal(b);
}, 0 );
// Total over this page
var pageTotal = api
.column(colIndex, { page: 'current'} )
.data()
.reduce( function (a, b) {
return intVal(a) + intVal(b);
}, 0 );
// Update footer
$( api.columns(colIndex).footer() ).html(
total
);
})
},
});
});
Contacts
projectid |
productid |
manufacturerid |
title |
quantity |
PAU a |
PAT a |
Coef a |
PVU a |
PVT a |
Profit a |
1 |
5 |
5 |
Title 1 |
10 |
130 |
1300 |
2 |
260 |
2600 |
1300 |
2 |
3 |
6 |
Title 2 |
10 |
100 |
1000 |
2 |
200 |
2000 |
1000 |
3 |
2 |
5 |
Title 3 |
10 |
50 |
500 |
2 |
100 |
1000 |
500 |
|
|
|
|
|
PAU a |
PAT a |
|
PVU a |
PVT a |
Profit a |
Run code snippetExpand snippet
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)