Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

201
Views
Server side scripting issue

I have written the server-side scripting to show a large amount of data and it's working fine, but I want to show the sum in the footer of the points column. The code is written in a laravel blade file.

The footer calls back function, not working it is showing me an error ie an undefined length object, please let me know where I am making the mistake.

<table class="table table-bordered yajra-datatable" width="100%" style="color:#8D1B6B;margin-top:20px;">
    <thead>
        <tr>
            <td><b>Sr No</b></td>
            <td><b>Date</b></td>
            <td><b>Activity Name</b></td>
            <td><b>Activity Marks</b></td>
            <td><b>My Rewards</b></td>
        </tr>
    </thead>
<tbody>

</tbody>
<tfoot>

</tfoot>
</table>

The script written for the above code is

<script>
        $(document).ready(function(){
            var table = $('.yajra-datatable').DataTable({
                processing: true,
                serverSide: true,
                ajax: "{{ route('abc') }}",
                columns: [
                    {data: 'DT_RowIndex', name: 'DT_RowIndex'},
                    {data: 'activityDate', name: 'activityDate'},
                    {data: 'activity', name: 'activity'},
                    {data: 'point', name: 'point'},
                    {
                        data: 'action',
                        name: 'action',
                        orderable: true,
                        searchable: true
                    },
                ],
                "footerCallback": function (row, data, start, end, display) {
                    var api = this.api(), data;
                    // 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;
                    };
                    // Total over all pages
                    data = api.column( 3 ).data();

                    total = data.length ? data.reduce( function (a, b) {
                        return intVal(a) + intVal(b);
                    }) : 0;

                    // Total over this page
                    data = api.column( 3, { page: 'current'} ).data(); pageTotal = data.length ? data.reduce( function (a, b) { return intVal(a) + intVal(b); } ) : 0;

                    // Update footer
                    $( api.column( 3 ).footer() ).html( '$'+pageTotal +' ( $'+ total +' total)' );
                }
            });

           
        });
    </script>
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!