After sort, fnGetNodes & fnGetData should return in new order

After sort, fnGetNodes & fnGetData should return in new order

kpm47kpm47 Posts: 6Questions: 0Answers: 0
edited February 2011 in General
Consider the following parameters for creating a datatable:

[code]{aaData: [['A', 8],['B', 2],['C', 43],['D', 294],['E', 1]], aoColumns: [{sTitle: 'Col1'},{sTitle: 'Col2'}]}[/code]

After initializing, [A,8] is returned when [code]dt.fnGetData(0);[/code] is called. Good. After sorting by the second column, however, [A,8] is still returned instead of [D,294]. The same goes for [code]dt.fnGetNodes(0);[/code]

Is there a way to get the data out in the order in which it's currently sorted? Thanks!

Kirk

Replies

  • kpm47kpm47 Posts: 6Questions: 0Answers: 0
    Forgot to mention - I'm using Datatables v1.7.5 with jQuery 1.5
  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    There isn't an API function for doing this at the moment, although it sounds like a very good candidate for a plug-in API method. This plug-in http://datatables.net/plug-ins/api#fnGetDisplayNodes is a be a good starting point, and in fact almost exactly what you want I think. The modification needed would be to loop over aiDisplayMaster rather than aiDisplay - the former is for before filtering the latter after filtering).

    Allan
  • kpm47kpm47 Posts: 6Questions: 0Answers: 0
    Thanks, Allan, I'll have a look. It would be great to have the option to always store the data array how it is shown, instead of keeping a copy of the original matrix around. Seems like a significant amount of memory could be saved by not holding onto that original array.

    Thanks!
  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    Either way the data needs to be stored somewhere - at the moment aiDisplay and aiDisplayMaster are index pointers to aoData (which is where the original data is stored), so I don't think there would be any benefit in terms of memory, and would make certain operations less efficient (for example sorting is just the rearranging of an index array at the moment, rather than shunting around the whole data array).

    Allan
This discussion has been closed.