Closed blutorange closed 5 years ago
Great deep dive! A PR would be much appreciated.
I made a PR here: https://github.com/primefaces-extensions/core/pull/84 Preserving backwards compatibility made it a bit harder, but it should work now.
Much appreciated and great work.
PrimeFaces Extensions: 7.0.2
Problem
The showcase gives an example for how to do sorting and another examples illustrating dynamic columns. When I try to use both features together, it does not work properly anymore:
Say the the user want sort sort by the 4th column. Clicking on the 4th column however results the rows getting sorted by the the first column. This is because internally, the column to sort by is searched by the literal value of the
sortBy
-attribute.A basic example to illustrate how this can be reproduced:
The same issue can probably be reproduced when you activate sorting for the example with dynamic columns in the showcase.
The user clicks on the second column:
But it sorts by the first column:
Cause
This is caused by how the column to sort by is searched for on the server. In
Sheet#getSortColRenderIndex
we find the following (simplified):It returns the first column with a
sortBy
attribute that matches the stored selection. In the case of dynamic columns, this attribute is the same for all columns, namely:So it always returns the first column, which results in the observed behavior.
Solution
I think this could be solved by storing the ID of the column instead of the value expression. When searching for the column, the value expression should still be tried first to preserve compatibility with older versions. I'm trying this now and if it works out, I'll submit a PR.