Drop-down to sort 2 hidden comumns
Drop-down to sort 2 hidden comumns
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
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
This discussion has been closed.
Replies
Allan
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.
> ReferenceError: Can't find variable: oTable
You need to define oTable :-). Just use `var oTable = $('#products').dataTable( {` in this case.
Allan
select.sort { float: right }
[/code]
I would think.
Allan