[Solved] Separate filter and sort header elements.

[Solved] Separate filter and sort header elements.

shredlucshredluc Posts: 11Questions: 0Answers: 0
edited March 2011 in General
Hey all,

I have been using 1.7.4 till today. I just upgraded and one particular piece of functionality is now broken. (It was most likely a bug. :P) I was able to specify 2 rows of column headers and have the sort functionality be applied to the second row. I would then place filter functions on the first row. Now the sort is applied to the first row. (Bug fixed?)

Because of this i have to roll back to version 1.7.4. Is there anyway to get such functionality back in 1.7.6?

This is how the table is defined:
[code]
"bPaginate": false,
"bInfo": false,
"bRetrieve": true,
"bAutoWidth": false,
"sDom":'<"generalsearch"f>',
"aaSorting": [[7,'asc'],[0,'asc'],[4,'asc']],
'aoColumnDefs':[
{"bSortable":false, "aTargets":[2,3,5,6]},
{"aTargets":[7], "sType":'pin-group'}
]
[/code]

This is how the table header looks like:
[code]







All
W
M
Q





All
C
P







All
<= 1%
<= 5%
<= 10%




Symbol
Date
W/M/Q
Strike
Put/Call
Position
Price
Diff
Percent


[/code]

So in 1.7.4 the sort triangles were positioned next to the words on the second header row. The Filter drop downs were in the first header row. Where there is no filter drop down, there is an empty cell. To sort i click the cell in the second header row. Now both filtering and sorting apply to the first header row, which is not what i want. This is also causing the filter drop downs to be ignored and instead to act like a sort event. Any ideas?

Replies

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    I think this was indeed a 'fix' that when into DataTables 1.7.5:

    "Updated: Previously when multiple cells were detected as unique to a column the last one would be given priority (i.e. sorting event handler etc). This is now no longer the case and the first will take priority."

    If you want to use sorting triggered on a different element, you could attach the sorting listener using http://datatables.net/api#fnSortListener .

    Sorry for the difference in functionality between the versions - but yes I felt that it was a bug (since the sort could be triggered when using a second row for input filtering like this: http://datatables.net/release-datatables/extras/FixedColumns/col_filter.html ) - which sounds rather like what you are doing :-) .

    Regards,
    Allan
  • shredlucshredluc Posts: 11Questions: 0Answers: 0
    edited March 2011
    Hey Allan,

    Thanks for the reply and your help! Yes, what i am doing is exactly as your example, except the functionality is reversed; the filtering is above the sorting. I will use the suggested fnSortListener to duplicate what i need. Thanks a lot!

    Edit: Well i got the sort active on the element i want, but i'm not sure how to disable it from the elements i don't. Also is it possible to move the sorting arrows to another element?
  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    You can use $('#example thead th').unbind('click'); just before you call fnSortListener to add the sorting events as you want. Regarding the sorting icons... hmmm - possibly but I think I might have an easier solution for the whole thing (i.e. no need for fnSortListener etc). You could try:

    [code]
    $('#example thead').append( $('#example thead tr:eq(0)')[0] );
    [/code]
    which will swap the headers around (to be done just after DataTables initialisation).

    Allan
  • shredlucshredluc Posts: 11Questions: 0Answers: 0
    You sir, are a genius! I dispensed with all the event handling and other what-not's and did a straight swap after everything is initialized. Thanks for all your help!
This discussion has been closed.