ServerSide no refresh the datas into the table
ServerSide no refresh the datas into the table
mbstef
Posts: 7Questions: 0Answers: 0
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]
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]
This discussion has been closed.
Replies
Allan
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.
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
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).
Allan
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..