ServerSide no refresh the datas into the table

ServerSide no refresh the datas into the table

mbstefmbstef Posts: 7Questions: 0Answers: 0
edited July 2012 in DataTables 1.9
Howdy,

i use the serverside processing to retrieve the datas for the datatable. As example by sorting into one column i retrieve a wellformated json back but into the datatable the new data will not shown, the same by click next or searching.

My Javascript:
[code]jc_data_table = {
init: function() {
if (!$('.dataTable').length) return;
var options = {
'bProcessing': true,
'bServerSide': true,
'sAjaxSource': $('.dataTable').attr('data-url'),
'sServerMethod': 'POST'
};
$('.dataTable').dataTable(options);
}
};
$(document).ready(function(){
jc_data_table.init();
});[/code]

Returned JSON:
[code]{"sEcho":1,"iTotalRecords":2759,"iTotalDisplayRecords":2759,"aaData":[["4062","HerrXXXX CH","Tel-1: Tel-2: Mobil: Fax: Email: ","Steuer-Nr.: Hinweise: Bici 55er RH"," "],["4061","HerrXXX CH","Tel-1: Tel-2: Mobil: Fax: Email: ","Steuer-Nr.: Hinweise: Bici 57er RH"," "],["and so on...."]]}[/code]

Replies

  • allanallan Posts: 63,700Questions: 1Answers: 10,501 Site admin
    That looks like it should work to me. Could you run the DataTables debugger over your table and post the debug code here please?

    Allan
  • mbstefmbstef Posts: 7Questions: 0Answers: 0
    Hi Allen,

    here is output, if i load the site without sorting or anything: http://debug.datatables.net/inekiz
    and this is the output, after click sorting by id DESC: http://debug.datatables.net/evejej

    You will see into Tables tab under Server Interaction that will load other values (ids) by server, but not showing.
  • allanallan Posts: 63,700Questions: 1Answers: 10,501 Site admin
    Thanks for the debug traces.

    sEcho is '1' in both of them. However, as the documentation says:

    > An unaltered copy of sEcho sent from the client side. This parameter will change with each draw (it is basically a draw count) - so it is important that this is implemented. Note that it strongly recommended for security reasons that you 'cast' this parameter to an integer in order to prevent Cross Site Scripting (XSS) attacks.

    http://datatables.net/usage/server-side

    So I guess that is the issue.

    Allan
  • mbstefmbstef Posts: 7Questions: 0Answers: 0
    Nope, that isn't it. I have cast all integers to this and nothing happens. Also the same problem like before.
  • allanallan Posts: 63,700Questions: 1Answers: 10,501 Site admin
    I'm going to need a bit more to go on if I'm going to be able to offer any assistance then... Ideally a link please.
  • mbstefmbstef Posts: 7Questions: 0Answers: 0
    edited July 2012
    Hi Allan,

    i cannot give a link, because this is a locally project development.

    So, i think, the retrieve JSON are ok, so the script are not needed. The HTML of the table looks like
    [code]


    ID
    Person
    Kontaktdaten
    Hinweise
     




    [/code]

    The javascript source looks like:
    [code](function($){
    jc_data_table = {
    init: function() {
    if (!$('.dataTable').length) return;
    var options = this.defaults();
    var table = $('.dataTable');
    if (table.attr('data-type') != undefined) {
    switch(table.attr('data-type')) {
    case 'customer':
    var opts = $this.customer(table,options);
    $.extend(options,opts);
    table.dataTable(options);
    return;
    }
    }
    },
    customer: function(obj, options) {
    var aoColumns = [];
    obj.children('thead').childrean('tr').children('th').each(function() {
    if ($(this).hasClass('no_sort'))
    aoColumns.push({'bSortable': false});
    else
    aoColumns.push(null);
    });
    var opts = {
    'bProcessing': true,
    'bServerSide': true,
    'sAjaxSource': obj.attr('data-url'),
    'sServerMethod': 'POST',
    'aoColumns': aoColumns
    }
    return opts;
    },
    defaults: function() {
    var options = {
    "oLanguage": {
    "sProcessing": "Bitte warten...",
    "sLengthMenu": "_MENU_ Einträge anzeigen",
    "sZeroRecords": "Keine Einträge vorhanden.",
    "sInfo": "_START_ bis _END_ von _TOTAL_ Einträgen",
    "sInfoEmpty": "0 bis 0 von 0 Einträgen",
    "sInfoFiltered": "(gefiltert von _MAX_ Einträgen)",
    "sInfoPostFix": "",
    "sSearch": "Suchen",
    "sUrl": "",
    "oPaginate": {
    "sFirst": "Erster",
    "sPrevious": "Zurück",
    "sNext": "Nächster",
    "sLast": "Letzter"
    }
    }
    };
    return options;
    }
    };
    $(document).ready(function($){
    jc_data_table.init();
    });
    })(jQuery);[/code]

    The Datatable work so perfect, but not refreshing the datas by sorting, searching, navigation etc. The JSON are all well-formed now (with casted integers and so on).
  • allanallan Posts: 63,700Questions: 1Answers: 10,501 Site admin
    It still sounds (and looks like from your debugger records) that sEcho is always being returned as 1, and it should not be. Can you load the page again, click to sort a column and then give me the debugger trace recorded after that has been done.

    Allan
  • mbstefmbstef Posts: 7Questions: 0Answers: 0
    Eyyyiiii.... anyone who can read is clear advantage ;)

    Ok, now into the php-ajax-script i use the Parameter sEcho to return the given sEcho as integer back and this will works. Thanks Allan..
This discussion has been closed.