Column reordering with server side processing.

Column reordering with server side processing.

RpiechuraRpiechura Posts: 98Questions: 3Answers: 14
edited April 2014 in ColReorder
So I'm working on making my server side processing work properly with column re-ordering. I'm curious how I figure out which column is where so that when the data gets back to the client I can put it into the correct column. Basically I need to know when I make the request from the client where each column is (if it's moved since the initialization) so that when I get the data back I can arrange the information in the array I feed aaData properly.

After further reading, it sounds like what I need to do is mess around with sName but I'm not sure I completely understand how to go about this. I've got a function that generates the columns for me when I'm doing the initialization for aoColumnDefs which sets stuff up as follows.
[code]
function createColumns(columns) {
columnArray = [];
jQuery.each(columns, function(i, value){
var obj = { sTitle: value, sName: value, aTargets: [i] };
columnArray.push(obj);
});
}
[/code]

So I'm making the array definitions for each column properly and when I inspect the oSettings before I make the request everything is being set up correctly. The question is now that I have what each column is named and where it originally was how do I process that data to put stuff in it's proper place when I get the data.

Replies

  • RpiechuraRpiechura Posts: 98Questions: 3Answers: 14
    edited April 2014
    I've seen http://datatables.net/release-datatables/extras/ColReorder/server_side.html and have looked at the code for it inside the examples page, but since you didn't add the server logic that you talk about with sName and mDataProp I'm not entirely sure what needs to be done.

    Something else I thought of, in my specific case I don't control the order that the data comes back in, so once I get down to the success of my .ajax call, I need some way to recognize that the data isn't in the proper order and rearrange it from the JSON that was returned.

    Not sure if it's going to help in this case, but the dataTables debug code is iwisuf.
  • RpiechuraRpiechura Posts: 98Questions: 3Answers: 14
    Oh man, I just started going through that DataTables debug code and holy cow that thing is useful! Serious props for making that thing, it shows everything! So notice how the columns I've re-arranged it so that ID, which is normally column 0 is now column 2. It's aTargets is pointed to 0 like we'd expect.

    I'm getting the data from opencongress.com using an intermediate ajax call and on the success I'm populating aDataSet by using the following code.
    [code]
    aDataSet = [];
    if (typeof data.people != 'undefined') {
    $.each(data.people, function (id, people) {
    $.each(people, function (id, person) {
    aDataSet.push([person.person_id, person.firstname, person.lastname, person.birthday]);
    });
    });
    }
    [/code]

    I'm aware that the order I'm pushing the data into the array is almost certainly the cause of the bug, I'm wondering how I would go about re-ordering the data so that it gets pushed into the correct order using sName or aTargets.
This discussion has been closed.