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

martincarlin87martincarlin87 Posts: 13Questions: 4Answers: 1
edited January 2015 in Free community support

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

  • allanallan Posts: 63,689Questions: 1Answers: 10,500 Site admin

    I couldn't see any docs on the new server side params

    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.

    but the behaviour is the same, first request works and subsequent ones are stuck on processing.

    That sounds to me like draw isn't being updated based on what is sent for each request. Might that be the case?

    Allan

  • martincarlin87martincarlin87 Posts: 13Questions: 4Answers: 1
    edited January 2015

    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 for sEcho and at the moment I'm just using the length 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) with 1 being the value for draw 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 or iColumns to say how many columns there are. This could be hard-coded of course but that doesn't seem as nice.

    # order logic
    order = ""
    if params[:iSortCol_0] != "" and params[:iSortingCols].to_i > 0
      for i in (0 .. params['iSortingCols'].to_i-1)
        order += "#{columns[ params['iSortCol_' + i.to_s].to_i ]} " + "#{params['sSortDir_' + i.to_s] }, "
      end
    else
      order += "id DESC"
    end
    

    Update 2

    Got the ordering working just by doing the following:

    column = params['order']['0']['column']
    dir = params['order']['0']['dir']
    order  "#{columns[column.to_i]} " + "#{dir}, "
    

    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.

  • allanallan Posts: 63,689Questions: 1Answers: 10,500 Site admin
    Answer ✓

    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 for sEcho - the client-side will send a draw parameter, which you parse as an integer (for security reasons) and then return to the client-side as the draw option in the JSON.

    Allan

  • martincarlin87martincarlin87 Posts: 13Questions: 4Answers: 1

    sorry, just realised it was a typo in my infoFiltered option and not the draw parameter.... it's been a long day re-learning everything I knew about datatables and I'm not done yet!

  • allanallan Posts: 63,689Questions: 1Answers: 10,500 Site admin
    Answer ✓

    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

  • martincarlin87martincarlin87 Posts: 13Questions: 4Answers: 1

    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.

  • allanallan Posts: 63,689Questions: 1Answers: 10,500 Site admin
    Answer ✓

    You might find the conversion documentation useful.

    Also, keep in mind that search() doesn't do an automatic redraw like fnFilter did. You need to call draw().

    Allan

This discussion has been closed.