Capturing The Total Number Of Records

Capturing The Total Number Of Records

tinker1123tinker1123 Posts: 22Questions: 0Answers: 0
edited October 2012 in General
Underneath the DataTables plugin you get a dynamic statement like
"Displaying 1 - 10 of 168 entries"

Is there way to detect when that statement gets updated and is there a way to capture the value of the total ( ie "168" )?

Thanks much in advance either way

Steve

Replies

  • girishmrgirishmr Posts: 137Questions: 0Answers: 0
    You can use

    [code]
    data['iTotalDisplayRecords']
    [/code]

    and store in a variable on successful ajax call
    ( you can get to see this info in firebug / chrome's dev tools XHR tab and check Either Response / JSON after successful ajax call)
    Hope this helps
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    http://datatables.net/plug-ins/api#fnPagingInfo will give you the current information and you can use the `draw` event or fnDrawCallback to see when the table is drawn.

    Allan
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    > data['iTotalDisplayRecords']

    Yes - as long as you are using server-side processing :-). Doesn't work for client-side processing.

    Allan
  • girishmrgirishmr Posts: 137Questions: 0Answers: 0
    Sorry I assumed Server side :)
  • tinker1123tinker1123 Posts: 22Questions: 0Answers: 0
    edited November 2012
    I got it working nicely. Thanks for the help everyone!

    This is roughly what I did:

    The HTML label at the top of my screen above the Datatables Plugin

    [code]


    ${number_of_records_found} Record(s) Found



    [/code]

    My Script

    [code]



    $.fn.dataTableExt.oApi.fnUpdateLabelNumRecords = function ( oSettings )
    {
    $("#number_of_records_found").html(oSettings.fnRecordsTotal());
    };



    $(document).ready(function() {
    $('#results_table').dataTable( {
    "bPaginate": true,
    "bProcessing": true,
    "bServerSide": true,
    "sScrollY": height,
    "bScrollCollapse":false,
    "sScrollX": "600px",
    "sServerMethod": "POST",
    "sAjaxSource": "/nsd/resultstable",
    "aoColumns": aoColumns,
    "fnDrawCallback": function(){this.fnUpdateLabelNumRecords();}

    } );
    } );

    [/code]
This discussion has been closed.