Sorting based on a whole row

Sorting based on a whole row

Ian DickinsonIan Dickinson Posts: 2Questions: 1Answers: 0
edited February 2010 in General
In my application, the rows in the table need to be sorted according to a function applied to a whole row. Basically, the sort key is a weighted average of a number of values from the row. Moreover, the weights in the weighted average are user-adjustable, so I need to be able to re-sort the table when the user changes a weight.

I've been reading the documentation, but I can't see a way to do this in DataTables as it stands since the assumption seems to be that sorting is based on values from a single column. Is that a correct characterisation?

The other way that I've thought to solve my requirement is to perform the sorting outside the table itself, then re-load the data. However, from looking at other forum posts, it's not clear to me how to do the reload.

Suggestions welcome.

Thanks,
Ian

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Hi Ian,

    Yes indeed this is possible (although it's not as trivial as standard sorting) - and quite a cool application (if possible I would be most curious if you could post one when you've implemented this?!). What you can do is make use of the second sorting system that DataTables provides called "Custom data source sorting" - http://datatables.net/development/sorting .

    It's still rather oriented towards individual columns still - however you do have access to the entire table. So what you want to do is construct an array of data which is then used to sort on. So I'd suggest having a hidden column with the sorting type needed for the plug-in, and put that column into aaSortingFixed (will always sort on this column then). And then hopefully it will fall into place :-)

    Regards,
    Allan
This discussion has been closed.