mDataProp (objects), bServerSide = true, and sNames

mDataProp (objects), bServerSide = true, and sNames

jamesWjamesW Posts: 2Questions: 0Answers: 0
edited October 2011 in DataTables 1.8
First, excellent piece of javascript magic. It would seem that I have a problem using DataTables 1.8.2. I'm using the mDataProp inside of aoColumns to use objects (specifically a map) in my server code as the cell values but at the same time I want to reorder the columns. I saw where I could do this with using the sNames properties for each column and the sColumns JSON to be returned. Everything works fine with those three arguments and my JSON so long as I don't change the sColumns JSON's order. I'm afraid I can't post example code but I did do some debugging and it would seem the error is on line 3600 where datatables.js is trying to use my data as an array of arrays (aaData[][]). I need the server to decide the column order and I'd like to keep the data in objects if at all possible. Does any one have any suggestions or am I going about doing this the wrong way?

Any help would be greatly appreciated. To reproduce just set the server side to true, set the columns mDataProp values and the sNames values. In the server script just reverse the order of the sColumns (and yes I double checked I'm not putting backwards names back on the client :-)) and you can see the error.

Replies

  • GregPGregP Posts: 487Questions: 8Answers: 0
    If you're using mDataProp, it doesn't matter what order the server returns the JSON in, everything is mapped according to name. Which is the real dilemna at hand. I don't have the answer for you, but if I'm not mistaken, the question is really "how can I have the server dictate the order?"
  • jamesWjamesW Posts: 2Questions: 0Answers: 0
    That is correct the question is: how can the server dictate the column order"? I realize that it wouldn't matter what order because datatables uses objects and not an array for it's cells but is there a way to reorganize the columns. I thought using the sName and sColumns JSON would work but apparently not. I guess I could use an array or arrays for data and just hide those with a special values but again it brings back the question of how to set the column order from the server. I don't want the data reorganized but rather the columns reorganized. Thanks for any help.
  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    sName and sColumns would affect the order in the traditional case, but if you're also using mDataProp, that changes things (converts aaData from array of array to array of objects)
  • johnadamsyjohnadamsy Posts: 13Questions: 0Answers: 0
    edited January 2012
    @jamesW You could add: [code] "oColReorder": {"aiOrder": [0, 1,2, 3 ][/code] in your client side script where the numbers 0...3 represent the number of columns you are displaying in your HTML table...since you are using a JSON object, that's the only easiest way to reorder your columns to the user..infact the easiest as compared to having it done on the server side
This discussion has been closed.