Event after an Ajax call is completed

Event after an Ajax call is completed

cmtsampaiocmtsampaio Posts: 3Questions: 0Answers: 0
edited May 2013 in General
Hi there,

Maybe this is a very noobish question but I'm sorry.. I gotta present it or I'll go crazy!

$(document).ready(function() {

$("#USERS").dataTable({
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"iDisplayLength": 5,
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": gurl_tbl_users,
"oLanguage": {
"sSearch": "Search Ticket:"
}
});
}

First off all, this implementation makes the datatable access the ajaxcall URL, retrieving and showing quite nicelly my data.

My question is, how do I register an event or funcion (or listen to one already implemented) so I can, by instance alert() the number of rows retrieved from the server?

I saw this one:
$(document).ready( function() {
$('#USERS').dataTable( {
"fnDrawCallback": function( oSettings ) {
alert( 'DataTables has redrawn the table' );
}
} );
} );

but I think there is some initialization issues about it... an alert() pops up...

Thanks in advance for any help given!

Replies

  • cmtsampaiocmtsampaio Posts: 3Questions: 0Answers: 0
    This is the text presented in the alert that I was speaking of:

    "DataTables warning (table id = 'game_sessions'): Cannot reinitialise DataTable.

    To retrieve the DataTables object for this table, pass no arguments or see the docs for bRetrieve and bDestroy"
  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    Just put your fnDrawCallback into the first initialisation object - don't try to initialise the table twice - you'll get a warning :-)

    Allan
  • cmtsampaiocmtsampaio Posts: 3Questions: 0Answers: 0
    edited May 2013
    OMG! So simple!
    working...
    1 - what is the best way to get the total number of rows?

    2 - And how do I customize the number of rows to show in the listbox (it's fixes to 10/25/50/1000),, I searched and found those values on the DataTables javascript file implementation...

    edited:

    Ok my first question was not that hard (LOL)

    //Init. Game Sessions table
    gs_tbl = $("#USERS").dataTable({
    "bJQueryUI": true,
    "sPaginationType": "full_numbers",
    "iDisplayLength": 20,
    "bProcessing": true,
    "bServerSide": true,
    "sAjaxSource": gurl_tbl_gs,
    "bFilter": false,
    "fnDrawCallback": function() {
    alert( gs_tbl.fnSettings().fnRecordsTotal() );
    }
    });

    for the second question I added:

    "aLengthMenu": [10,20,30,40],

    nice!

    PS! Thanks for the answer Allan! :)
  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    > 1 - what is the best way to get the total number of rows?

    Currently with this plug-in: http://datatables.net/plug-ins/api#fnPagingInfo . v1.10 will have something similar built in.

    > 2 - And how do I customize the number of rows to show in the listbox (it's fixes to 10/25/50/1000)

    As you say - aLengthMenu :-)

    Allan
This discussion has been closed.