Column reordering with server side processing.
Column reordering with server side processing.
Rpiechura
Posts: 98Questions: 3Answers: 14
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.
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.
This discussion has been closed.
Replies
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.
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.