Drop-down to sort 2 hidden comumns

Drop-down to sort 2 hidden comumns

LumenLumen Posts: 3Questions: 0Answers: 0
edited November 2013 in General
Hi,

I have spend the last couple of hours looking for a selution, I want a dropdown that will sort two hidden columns in my table.
"Price High to Low" "Price Low to High "Rating High to Low" "Rating Low to High"

I have tried this:

[code]
$('#sortBy').change( function () {

switch ($(this).val()) {
case "_none_": // first option chosen, not associated with any column, do some default
oTable.fnSort( [ [0,'asc'] ] );
break;

case "name_asc":
oTable.fnSort( [ [4,'asc'] ] );
break;

case "name_desc":
oTable.fnSort( [ [4,'desc'] ] );
break;

case "price_asc":
oTable.fnSort( [ [5,'asc'] ] );
break;

case "price_desc":
oTable.fnSort( [ [5,'desc'] ] );
break;
}
[/code]
html:
[code]

Sort By...
Price (asc)
Price (desc)
Rating (asc)
Rating (desc)

[/code]

fromt he post:
http://www.datatables.net/forums/discussion/6195/using-select-dropdown-to-sort-columns/p1

But it's not working. Could anyone be so kind to give me a working example?
Thank you very much in advance <3

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Your code looks about right to me. Can you please link us to a test case showing the issue so we can take a look and say why it might not be working.

    Allan
  • LumenLumen Posts: 3Questions: 0Answers: 0
    edited November 2013
    oke I made a test page:
    http://bodyspecial.com/DataTableTest.html#

    Thanking you in advance :)

    p.s. I would also love (if we get it working) the drop down menu to be placed in the top bar on the left.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Javascript error on the console:

    > ReferenceError: Can't find variable: oTable

    You need to define oTable :-). Just use `var oTable = $('#products').dataTable( {` in this case.

    Allan
  • LumenLumen Posts: 3Questions: 0Answers: 0
    great!!! thank you so much, how do I get the drop-down menu in the top-bar on the left side please?
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    [code]
    select.sort { float: right }
    [/code]

    I would think.

    Allan
This discussion has been closed.