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
![martincarlin87](https://secure.gravatar.com/avatar/4911111fc02f783c08449e83c13c6105/?default=https%3A%2F%2Fvanillicon.com%2F4911111fc02f783c08449e83c13c6105_200.png&rating=g&size=120)
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
draw
isn'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
draw
and what it does, I thought it was just the replacement forsEcho
and at the moment I'm just using thelength
param 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
draw
param 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
draw
that 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)
with1
being the value fordraw
but 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
iSortingCols
or equivalent to signify that a column is to be sorted oriColumns
to 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
draw
text 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.
draw
is basically the replacement forsEcho
- the client-side will send adraw
parameter, which you parse as an integer (for security reasons) and then return to the client-side as thedraw
option in the JSON.Allan
sorry, just realised it was a typo in my
infoFiltered
option and not thedraw
parameter.... 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
fnFilter
yet and realised I'm still using.dataTable
rather than.DataTable
but 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 likefnFilter
did. You need to calldraw()
.Allan