Datatable not getting Auto-refreshed after click on header for sorting
Datatable not getting Auto-refreshed after click on header for sorting
I am implementing sorting (Order by) for dataTable at server side. All sessms to be fine Even my data gets properly sorted (I can check that in firebug.). Now the problem is , datatable is not getting reloaded after that, and "processing..." continues to appear. Any clue on where to write function for reload. I know it can be done by
[code] oTable.fnDraw(true); [/code]
but I dont know where to write it after header is clicked for sorting. Let me know if you need any code snippet to debug.
[code] oTable.fnDraw(true); [/code]
but I dont know where to write it after header is clicked for sorting. Let me know if you need any code snippet to debug.
This discussion has been closed.
Replies
[code]
var oTable = $('#datatable').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "datatableprocessor",
"sPaginationType": "full_numbers",
"fnRowCallback": function (nRow, aData, iDisplayIndex) { return nRow; },
"fnServerData": function ( sSource, aoData, rfrshCallbk ) {
$('.search').each(function(index) {
var name = $(this).attr("name");
var tempName = name.replace("search","condition" );
var condition = $("[name='"+tempName+"']").val();
var value = $(this).val();
aoData.push({ "name": name, "value": value+""+condition });
});
aoData.push({ "name": "queryId", "value": "test" });
$.ajax( {
"dataType": 'json',
"type": "POST",
"url": sSource,
"data": aoData,
"success": rfrshCallbk
} );
},
"aoColumnDefs": [
{ "sName": "c.id", "aTargets": [ 0 ] },
{ "sName": "c.firstname", "aTargets": [ 1 ] },
{ "sName": "c.lastname", "aTargets": [ 2 ] },
{ "sName": "c.telephone", "aTargets": [ 3 ] }
]
} );//
[/code]
Above is the source code for dartaTable.
"success": function(json){
alert(JSON.stringify(json));
rfrshCallbk(json);
}
In both cases , when I reload my page or do sorting json string is same .. ??!!?? don't know what is wrong ??!!??
1. Give us a link to we can see what is going wrong
2. If you can't do that use the debugger and give us the debug code
Allan
Sorting isn't the issue, I can see in debugger output is well sorted, what do you expect when you say debug code?? I am posting response from firebug:
[quote]
headers:
Response Headers
Content-Length 204
Content-Type application/json;charset=UTF-8
Date Fri, 21 Sep 2012 14:52:33 GMT
Server Apache-Coyote/1.1
Request Headers
Accept application/json, text/javascript, */*; q=0.01
Accept-Encoding gzip, deflate
Accept-Language en-us,en;q=0.5
Connection keep-alive
Content-Length 546
Content-Type application/x-www-form-urlencoded; charset=UTF-8
Cookie JSESSIONID=0EE2A4C2CB916D2152105944B790FB7C; GUEST_LANGUAGE_ID=en_US; COOKIE_SUPPORT=true; LOGIN=74657374406c6966657261792e636f6d; SCREEN_NAME=7a336979515a50695634553d
Host localhost:8080
Referer http://localhost:8080/Spring3HibernateMaven/index
User-Agent Mozilla/5.0 (Windows NT 6.1; rv:15.0) Gecko/20100101 Firefox/15.0.1
X-Requested-With XMLHttpRequest
[/quote]
[quote]
post parameters:
bRegex false
bRegex_0 false
bRegex_1 false
bRegex_2 false
bRegex_3 false
bSearchable_0 true
bSearchable_1 true
bSearchable_2 true
bSearchable_3 true
bSortable_0 true
bSortable_1 true
bSortable_2 true
bSortable_3 true
iColumns 4
iDisplayLength 10
iDisplayStart 0
iSortCol_0 0
iSortingCols 1
mDataProp_0 0
mDataProp_1 1
mDataProp_2 2
mDataProp_3 3
queryId test
sColumns c.id,c.firstname,c.lastname,c.telephone
sEcho 5
sSearch
sSearch_0
sSearch_1
sSearch_2
sSearch_3
sSortDir_0 asc
search_c.firstname manmohan%
search_c.lastname vyas%
[/quote]
[quote]
response:
{"iTotalDisplayRecords":2,"iTotalRecords":57,"aaData":[[8,"manmohan","vyas","34343"],[11,"manmohan1","vyas134","sd"],[22,"manmohan23","vyas23","8983876002"],[23,"manmohan23","vyas23","asdf"]],"sEcho":"1"}
[/quote]
please let me know if you need something else.
Use the DataTables debugger: http://debug.datatables.net . Try sorting the columns a couple of times before running the debugger so we can see the broken state.
> "iTotalDisplayRecords":2,"iTotalRecords":57,
That looks very wrong to me. Firstly you've got 4 records in your response, not 2 or 10 or anything else. So where do the 2 and 57 come from? Are you also remembering that sEcho changes on every request?
Do you really need server-side processing? Are you going to be working with > 50'000 rows?
Allan
great debugging tool, haven't ever imagine that is possible.
Yes I need to work with more than millions of record. I am currently doing POC for dataTables. I thought "iTotalDisplayRecords" and "iTotalRecords" are just used for display purpose, so they were hardcoded values. Have corrected that also, but still result is same.
here is the debug code:
http://debug.datatables.net/evuhig.
please let me know if you need any further help, if you want I can also post my java processor.
Can you change it to:
[code]
function(sSource, aoData, rfrshCallbk, oSettings) {
$(".search").each(function(index) {
var name = $(this).attr("name");
var tempName = name.replace("search", "condition");
var condition = $("[name='" + tempName + "']").val();
var value = $(this).val();
aoData.push({
name: name,
value: value + "" + condition
});
});
aoData.push({
name: "queryId",
value: "test"
});
oSettings.jqXHR = $.ajax({
dataType: "json",
type: "POST",
url: sSource,
data: aoData,
success: function(json) {
alert(JSON.stringify(json));
rfrshCallbk(json);
}
});
}
[/code]
and then rerun the debugger.
If you are able to give me a link t the page that would be really useful to see what is going on quicker, but another debug trace will hopefully be enough.
Allan
can you please check if this is working for you http://116.203.73.118:8080/Spring3HibernateMaven/index
> "sEcho": "1"
For draw number three (which your debug trace is from), that is wrong. See http://datatables.net/usage/server-side :
> 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.
Allan
Thanks again :)