Mottie / tablesorter

Github fork of Christian Bach's tablesorter plugin + awesomeness ~
https://mottie.github.io/tablesorter/docs/
2.6k stars 753 forks source link

two header lines issues #1362

Open assachs opened 7 years ago

assachs commented 7 years ago

Hello, i have some issues with two header lines. I'm not sure, if they belong together

sortList count's second row (http://jsfiddle.net/pehruqqL/1/): sortList: [[1,0]] sorts the second col of the second row.

headers counts both rows: http://jsfiddle.net/pehruqqL/2/ headers: { 4: {sorter:false} //first row cols 0 - 2, second cols 3 - 11 }

changing the sorter of the second row has no effect: headers: { 4: {sorter:'customParser'} //first row cols 0 - 2, second cols 3 - 11 } (it's working with class-attribute)

Mottie commented 7 years ago

Hi @assachs!

Sorry for not responding earlier. I'm still catching up with issues after returning from vacation.

The issue you've encountered is as intended... a table will always have a set number of columns, but may not always have the same number of header cells.

headers

sortList

I hope that makes things clearer.

assachs commented 7 years ago

Hello, thanks for your reply. I hope you had good vacations ;)

I understand the difference between headers and and sortlist now. But i still think there is a problem with headers and two header rows.

Look at the following examples: All of them use a custom parser to sort 01,03, 2 instead of 01, 2, 03

http://jsfiddle.net/ke52bbf1/ The parser is added to the last column with class attribute. It is also added to 3 (4th column) with "headers"-option. It is working for both columns.

Now, i have a two header row example: http://jsfiddle.net/g6srzo87/ The parser is added to the last column with class attribute. It's working. The parser is added to cell 3 (= second column). It is NOT working. I think the second column should be the associated column.

Mottie commented 7 years ago

The problem is that the headers must be set as if the index is of all header cells. The third column header cell is represented by "Cell 4" which has a (zero-based) index of 4.

Hmm, yes it does appear that there is a problem with the way the headers option is being parsed when there are multiple header rows. I could fix it, but if I did it would break all backwards compatibility 😿 I'll fix when I get to work on Abelt again.

To get around this problem, set the parser by data-attribute, class name or completely disable the first header row by adding a class name of "tablesorter-ignoreRow" to the <tr>; but this also disables sorting.

JohnSmall commented 6 years ago

With two row headers I found I could add the sort buttons only to the second row, not the first row by setting

`selectorHeaders: '> thead > tr:last-child > th'`

But If I then want to set some columns not to be sorted e.g.

headers: {0: {sorted: false}}

Then the first column is still sortable.

But if I don't set selectorHeaders then I can disable some columns, but only for the first row.

If I use the class name "tablesorter-ignoreRow" on the first in the header then it disables sorting for that row, leaves sorting for the other row, but doesn't allow me to set columns not to be sorted.

Mottie commented 6 years ago

Hi @JohnSmall!

The key should be set to sorter not sorted - demo

headers: {
  0: { sorter: false }
}