Upgrading from 1.9.4 to 1.10.2 Confusions About What Is Deprecated and Their Equivalents
Upgrading from 1.9.4 to 1.10.2 Confusions About What Is Deprecated and Their Equivalents
I've been upgrading from version 1.9.4 to 1.10.2 over the last couple of days and got on fine so far but today I am working on upgrading a table that uses AJAX and have run into a few problems.
The first was that I had to change my server side script from using the sSearch param to search[value] but I couldn't see any docs on the new server side params and worked it out by examining the ajax request being sent.
The next was to change sEcho to length and iDisplayStart to start as well as sort out the new AJAX initialisation code:
// irrelevant initialisation options removed
'deferRender': true,
'ordering': false,
'processing': true,
'serverSide': true,
'ajax': {
'url': '/cdr/ajax_fetch_all',
'type': 'POST',
'data': function (d) {
d.organisation_id = organisation_id;
d.direction = $('#col2_filter').val();
d.month = $('#month_filter').val().split('_')[0];
d.year = $('#month_filter').val().split('_')[1];
}
},
//
This is all fine and the first request works but subsequent requests are stuck on "processing" even when the request has completed and returned valid JSON with no errors on the console.
I was looking for some documentation that might have a list of deprecated functions and their equivalents but can't seem to find anything like that.
e.g. is this still how to call a callback function after an ajax request:
'fnRowCallback': function(nRow, aData,iDisplayIndex) {
$('td:eq(6)', nRow).addClass('text-right');
return nRow;
},
This seems to work but the naming convention makes me think it's deprecated.
Also, am I still using deprecated keys in my response?
e.g. sEcho, iTotalRecords, iTotalDisplayRecords and aaData?
and what about the params iSortingCols, sSortDir_*?
Any help would me greatly appreciated as I can't work out why the first request is fine but the ones made afterwards are broken.
Martin
Update
I was looking through all the questions and from one I think I found the new names so I changed:
sEcho to draw
iTotalRecords to recordsTotal
iTotalDisplayRecords to recordsFiltered
aaData to data
but the behaviour is the same, first request works and subsequent ones are stuck on processing.
This question has accepted answers - jump to:
Answers
They are detailed in the server-side processing manual page.
Basically, anything that was Hungarian notation is now deprecated, in favour of the camelCase notation parameters.
That sounds to me like
drawisn't being updated based on what is sent for each request. Might that be the case?Allan
Hi Allan,
Many thanks for your comment, I swear that I was looking for that exact page for ages, I'm sure I clicked and read every page that mentioned anythings server side so apologies for my ignorance.
I think you might be right but I'm just trying to read about
drawand what it does, I thought it was just the replacement forsEchoand at the moment I'm just using thelengthparam for it, should I be using some other value for it?I read your note about casting it to integer so should I just be outputting the
drawparam the server received but cast it as an int and back to a string (Rails can't concat ints with strings)?Thanks again,
Martin
Update
Just tried returning the value for
drawthat the server receives and that works fine but only thing is that the filter text is wrong now.e.g.
Showing 1 to 15 of 205 entries (filtered1 from 29,697 total entries)with1being the value fordrawbut I'm guessing that is what you meant by it not being updated for each request so I think that's all I need to figure out now is what to do with it server side.Basically, if there is an up-to-date example server side script then I should be able to use that as a reference because at the moment I'm a bit confused as to how to update my ordering logic since there's no
iSortingColsor equivalent to signify that a column is to be sorted oriColumnsto say how many columns there are. This could be hard-coded of course but that doesn't seem as nice.Update 2
Got the ordering working just by doing the following:
Initially I was using a loop like before but for some reason that was keeping the initial sorted column in the
ORDER BY.Everything seems to be working now but not sure why the
drawtext is appearing in the filter message under the table.That doesn't really seem to make much sense as to why that would happen! I've never seen that before.
drawis basically the replacement forsEcho- the client-side will send adrawparameter, which you parse as an integer (for security reasons) and then return to the client-side as thedrawoption in the JSON.Allan
sorry, just realised it was a typo in my
infoFilteredoption and not thedrawparameter.... it's been a long day re-learning everything I knew about datatables and I'm not done yet!You can make it use the old method if you want btw - 1.10 is backwards compatible. There is a Legacy note in the server-side processing documentation showing how to enable it.
Allan
Yeah, I'm still a little confused, not managed to upgrade
fnFilteryet and realised I'm still using.dataTablerather than.DataTablebut if I change it to the latter and use the new new method it doesn't seem to work but everything works the way I want it at the moment despite it being a mish-mash of old and new code but I'm sure I'll figure it all out in time, thanks for your help.You might find the conversion documentation useful.
Also, keep in mind that
search()doesn't do an automatic redraw likefnFilterdid. You need to calldraw().Allan