Capturing total number of records?

Capturing total number of records?

JonasNJJonasNJ Posts: 2Questions: 1Answers: 0

I am trying to capture the total number of records shown in a given DataTable. Unfortunately I cannot link to the site since it's on a secure platform.
I have searched the forum for answers on how to do it but none of the similar posts made any sense to me.
I have also tried the method ( like this:

// Extract total number of records
        var showNumberOfRecords = function () {
            var currentTable = $('#example').DataTable();
            var info =;
                'You have a total of '+info.recordsTotal+' employees'

but that just returns an object with no records:

I noticed that the DataTable is showing the total number of records here:

and I found the responding code in datatables.bundle.js on line 15777:

but I don't know how to extract that data and don't even understand the syntax of the code...

The DataTable gets data from an ajax call, but Server-side processing is set to false, since searching and ordering ect. should be processed in the browser.

I hope I have explained the issue well enough and any help would be greatly appreciated.
I apologize for the lack of technical understanding on my part - I am but a novice developer :)

This question has an accepted answers - jump to answer


  • kthorngrenkthorngren Posts: 19,462Questions: 26Answers: 4,610
    Answer ✓

    Its possible that you are executing the showNumberOfRecords function before Datatables has completed initialization. The ajax request is asynchronous so the code keeps executing while waiting for the ajax response. Move the call to this function into the initComplete option.


  • JonasNJJonasNJ Posts: 2Questions: 1Answers: 0

    @kthorngren Kevin, my man, that did the trick. Thank you, I truly appreciate it.

    For anyone experiencing the same issue, here is my updated code:

    // Private functions
            var initDatatable = function () {
                dt = $("#" + param_dataTableID).DataTable({
                    searchDelay: 500,
                    processing: true,
                    serverSide: false,
                    stateSave: true,
                    ajax: {
                        url: param_apiURL,
                        dataSrc: 'data'
                    columns: param_columns,
                    columnDefs: param_columnDefs,
                    // Extract and show total number of records after initialization
                    initComplete: function(settings, json) {
                        var currentTable = $("#" + param_dataTableID).DataTable();
                        var info =;
                            'You have a total of '+info.recordsTotal+' employees'
                table = dt.$;
                // Re-init functions on every table re-draw -- more info:
                dt.on('draw', function () {
Sign In or Register to comment.