Problem for sum each column + filter rows

Problem for sum each column + filter rows

richard03257richard03257 Posts: 1Questions: 0Answers: 0

Hello,
I want to make a table to be able to help me make price comparisons.
Explanations:
In my table I have <th> :
- 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?

The script i use : https://jsfiddle.net/#&togetherjs=xsj2oRC44B

html :

<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css" />
    <!-- /DataTables js / -->
    <script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.js"></script>
<table id="example" class="display nowrap table1" cellspacing="0" width="100%">
            <thead>
                <tr>
                    <th>projectid</th>
                    <th>productid</th>
                    <th>manufacturerid</th>
                    <th>title</th>
                    <th>quantity</th>
                    <th>PAU a</th>
                    <th>PAT a</th>
                    <th>Coef a</th>
                    <th>PVU a</th>
                    <th>PVT a</th>
                    <th>Profit a</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>1</td>
                    <td>5</td>  
          <td>5</td>        
          <td>Title 1</td>  
          <td>10</td>       
          <td>130</td>
          <td>1300</td>     
          <td>2</td>        
          <td>260</td>      
          <td>2600</td>     
          <td>1300</td>     
                </tr>
        <tr>
                    <td>2</td>
                    <td>3</td>  
          <td>6</td>        
          <td>Title 2</td>  
          <td>10</td>       
          <td>100</td>
          <td>1000</td>     
          <td>2</td>        
          <td>200</td>      
          <td>2000</td>     
          <td>1000</td>     
                </tr>
        <tr>
                    <td>3</td>
                    <td>2</td>  
          <td>5</td>        
          <td>Title 3</td>  
          <td>10</td>       
          <td>50</td>
          <td>500</td>      
          <td>2</td>        
          <td>100</td>      
          <td>1000</td>     
          <td>500</td>      
                </tr>
            </tbody>
            <tfoot>
        <tr>
                    <th></th>
                    <th></th>
                    <th></th>
                    <th></th>
                    <th></th>
                    <th>PAU a</th>
                    <th>PAT a</th>
                    <th></th>
                    <th>PVU a</th>
                    <th>PVT a</th>
                    <th>Profit a</th>
                </tr>
            </tfoot>
        </table>
    </div>
<script>
var intVal = function ( i ) {
    return typeof i === 'string' ?
    i.replace(/[\$,]/g, '')*1 :
    typeof i === 'number' ?
    i : 0;
};
 
$(document).ready(function() {
    var table = $('#example').DataTable( {
        responsive: true,
        scrollX: true,
        scrollCollapse: true,
        paging: true,
        lengthChange: false,
        lengthMenu: [ [10, 25, -1], [10, 25, "All"] ],
        "order": [[ 0, "asc" ]],
        "footerCallback": function ( row, data, start, end, display ) {
            var api = this.api(), data;
            var sumColumns = [5,6,8,9,10]
            sumColumns.forEach(function(colIndex){
            // Total over all pages
                var total = api
                    .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
                );
            }) 
        },
        buttons: ['pdf']
    });
    table.buttons().container()
    .appendTo( '#example_wrapper .small-6.columns:eq(0)' );
});   
</script>

Thanks for help

This discussion has been closed.