Sorting - Using external buttons for Asc and Desc
Sorting - Using external buttons for Asc and Desc
Hello,
I would like to be able to sort my table using external links or buttons.
Currently I am :
[code]
var thisHeadinput = $('.dataTables_scrollHeadInner').find('table > thead > tr > th');
thisHeadinput.unbind('click.DT');
$('#accountSortList li').click(function() {
historyPage.table.fnSortListener($('#accountSortList'), 3);
});
[/code]
There is an external div with a list that has two LI links that say "Sort A->Z" and "Sort Z->A"
The links work to sort, but i can continue to click on either and it will switch the sorting depending on the previous sort.
(you can keep clicking the same link and it resorts by reversing the sort of the previous sort)
I want the LI links to just sort in one direction, no matter how many times you click the same link.
Is this possible? I dont see any info on how to specify a direction.
Thanks.
I would like to be able to sort my table using external links or buttons.
Currently I am :
[code]
var thisHeadinput = $('.dataTables_scrollHeadInner').find('table > thead > tr > th');
thisHeadinput.unbind('click.DT');
$('#accountSortList li').click(function() {
historyPage.table.fnSortListener($('#accountSortList'), 3);
});
[/code]
There is an external div with a list that has two LI links that say "Sort A->Z" and "Sort Z->A"
The links work to sort, but i can continue to click on either and it will switch the sorting depending on the previous sort.
(you can keep clicking the same link and it resorts by reversing the sort of the previous sort)
I want the LI links to just sort in one direction, no matter how many times you click the same link.
Is this possible? I dont see any info on how to specify a direction.
Thanks.
This discussion has been closed.
Replies
Allan
I was trying this after posting, but it was not working. I would sort the first time, but then not after that.
THE ISSUE WAS.....
I was using an OL with and
Can you explain us your solution, or show us your table online, because i don't understand your explanation...
I'm trying to use buttons or links, in the table's page but outside the table, to change the sorting.
I would very grateful for your help !
thanks,
You just have to create a div, a button... with an id (here "buttonId"), the you can sort the column as you want (asc or desc) :
[code]
var oTable = $('#example').dataTable();
$('#buttonId').click(function(){
oTable.fnSort([ [6,'asc']] );
});
[/code]
then in your htm :
Sort ascending on column 6
[code]
allCols = {
'2' : 'val1',
'3' : 'val2',
};
for(var allCol in allCols) {
(function() {
// This element \/ is in a div with a ul: li ▲ Asc
$('#'+allCols[allCol]+'SortList li').click(function() {
historyPage.table.fnSort([index, $(this).attr('data-sortDir')]);
});
})();
}
[/code]
And in case anyone is interested....
I am using the filtering plugin.
After some searching and testing trying to do range filtering, I ended up using the plugin, and then just moving the inputs that the default plugin generates and moving them into a div that appears when you rollover the header row.
Seems to work well.