A button that "refreshes" the data in the Table - using Server-Side

A button that "refreshes" the data in the Table - using Server-Side

diondudiondu Posts: 24Questions: 0Answers: 0
edited May 2010 in General
Hey people, I would like to put a button in my page that when clicked refreshs the data in the table.

How can I do this.

Example:

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    A call to fnDraw will do the trick: http://datatables.net/api#fnDraw

    Allan
  • diondudiondu Posts: 24Questions: 0Answers: 0
    edited May 2010
    Allan, sorry about the question. I'm novice in jquery. I put this in my button listener but it didn't work:

    [code][/code]
    Is that correct?

    [code]
    $(document).ready(function() {
    oTable = $('#tblTabela').dataTable( {
    "bProcessing": true,
    "bServerSide": true,
    "sAjaxSource": "VINCULADOS2_ajax.asp",
    "sPaginationType": "full_numbers",
    "fnServerData": function ( sSource, aoData, fnCallback ) {
    var vlrAgrupador = document.getElementById("cnpjEncontrado").value;
    aoData.push( { "name": "vlrAgrupador", "value": vlrAgrupador } );
    $.getJSON( sSource, aoData, function (json) {
    fnCallback(json)
    } );
    },
    "fnRowCallback": function( nRow, aData, iDisplayIndex ) {
    $(nRow).addClass('gradeC');
    return nRow;
    }
    } );
    } );
    [/code]
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    That will work if oTable is a global variable (i.e. declared outside the scope of a function). At least I think it should! However, what I would recommend is that you don't use DOM0 events (onclick and the like) and instead use jQuery to do the events for you. If you add an ID to your input of "button" (or whatever) then you can do:

    [code]
    $(document).ready(function() {
    var oTable = $('#tblTabela').dataTable( {
    "bProcessing": true,
    "bServerSide": true,
    "sAjaxSource": "VINCULADOS2_ajax.asp",
    "sPaginationType": "full_numbers",
    "fnServerData": function ( sSource, aoData, fnCallback ) {
    var vlrAgrupador = document.getElementById("cnpjEncontrado").value;
    aoData.push( { "name": "vlrAgrupador", "value": vlrAgrupador } );
    $.getJSON( sSource, aoData, function (json) {
    fnCallback(json)
    } );
    },
    "fnRowCallback": function( nRow, aData, iDisplayIndex ) {
    $(nRow).addClass('gradeC');
    return nRow;
    }
    } );

    $('#button').click( function () {
    oTable.fnDraw();
    } );
    } );
    [/code]
    In the long run using jQuery events can save a lot of grief :-) Also it's good from the stand point of progressive enhancement.

    Regards,
    Allan
This discussion has been closed.