Perform sort on individual columns in the frontend

Perform sort on individual columns in the frontend

KadrianKadrian Posts: 4Questions: 0Answers: 0
edited September 2012 in General
Hi,
after the tutorial on server-side data, I've got it all up and running with a python backend (and the Flask-webframework).
Runs really good so far, thanks, very good work guys!

Now in the backend I sometimes do some post-processing of the columns to add some HTML e.g.:
[code]
for entry in aaData:
# link to customer name
customer = Customer.find_by_name(entry[1])
entry[1] = ('' + customer.name + "")
[/code]

or to aggregate a number:
[code]
for entry in aaData:
# add net value
netvalue = 0
for product in BoughtProduct.get_all_by_orderid(id):
netvalue += product.price
entry.append(netvalue)
[/code]

The numbers are displayed nicely in the table, but how can I perform a sort on the displayed values now, for example on the calculated "netvalues" ? This must happen in the frontend somehow, doesn't it?

Thanks in advance!
Kai

Replies

  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    Yes - is the numeric data in a column? If you've enabled DataTables on that table, just click the column header. Does that work?

    Allan
  • KadrianKadrian Posts: 4Questions: 0Answers: 0
    edited September 2012
    Yes its numeric data, but if I just click the column header, another ajax-request is sent (server-side processing), which tells my database to do an 'ORDER BY' on that column.

    But this column doesn't exist in the database because its only created in post-processing with:
    [code]entry.append(netvalue)[/code]

    So I don't want to send an ajax request when I click on this special header, but instead perform an individual search. I know that there is "bSortable: false", which simply turns sorting off for a column, but I need some kind of "bSortableOnDisplayedData: true"

    How can I do that?
  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    There is no way to do that I'm afraid. If you are using server-side processing, then the processing is done at the server-side :-). There is no way to split the processing between the client-side and the server-side, so if you want to allow sorting on a generated column, the server will need to do it.

    Allan
  • KadrianKadrian Posts: 4Questions: 0Answers: 0
    Ok, I was afraid you'd say that ^^
    Anyway, thanks for the comment, probably I've got to do some more complicated SQL-queries to solve this...
This discussion has been closed.