primefaces / primefaces

Ultimate Component Suite for JavaServer Faces
http://www.primefaces.org
MIT License
1.79k stars 760 forks source link

Column: Automatic sort if groupRow is set #8502

Closed fabermundi closed 2 years ago

fabermundi commented 2 years ago

Describe the defect When having a column that has the property "groupRow" set to "true" and the "sortBy" property is set then this column is automatically sorted.

Environment:

Expected behavior A column where "sortOrder" is not set should not be sorted by default. At the example below the column is sorted automatically.

Example XHTML

<h:form>
    <p:dataTable value="#{groupRow.data}" var="data">
        <p:column sortBy="#{data}" filterBy="#{data}" groupRow="true">
            <h:outputText value="#{data}" />
        </p:column>
    </p:dataTable>
</h:form>

Example Bean

@Named
@ViewScoped
public class GroupRow implements Serializable {
    private static final long serialVersionUID = 4485167715842515932L;

    private List<Integer> data = null;

    public List<Integer> getData() {
        if (data == null) {
            data = new ArrayList<>();
            for (int i = 10; i >= 1; i--)
                data.add(i);
        }
        return data;
    }
}
tandraschko commented 2 years ago

I get: Caused by: javax.faces.FacesException: Data type should be java.util.List or javax.faces.model.ListDataModel instance to be sortable.

and thats by design

fabermundi commented 2 years ago

Thanky ou for the reply.

Sorry I copied an old version of the code.

This is the right one:

@Named @ViewScoped public class GroupRow implements Serializable { private static final long serialVersionUID = 4485167715842515932L;

private List<Integer> data = null;

public List<Integer> getData() {
    if (data == null) {
        data = new ArrayList<>();
        for (int i = 10; i >= 1; i--)
            data.add(i);
    }
    return data;
}

}

Should I edit my report or create a new issue?

tandraschko commented 2 years ago

i will reopen, please edit and next time try your sample before creating a issue, thats wasting our time.

fabermundi commented 2 years ago

Thank you and sorry again.

tandraschko commented 2 years ago

Currently this is by design: https://github.com/primefaces/primefaces/blob/fc76cdf76b8ba4f31833de176b0c2bb5106081f3/primefaces/src/main/java/org/primefaces/model/SortMeta.java#L97-L100

but it was NOT in 8.0 codebase

tandraschko commented 2 years ago

See: https://github.com/primefaces/primefaces/issues/6742

@Rapster should we just close this issue, as its by design? 8.0 was indeed unsorted - no idea why we introduced it TBH

Rapster commented 2 years ago

To make "group" feature happens, sorting was and still is the default strategy. See 8.0:

        ValueExpression groupByVE = null;
        ValueExpression tableSortByVE = table.getValueExpression(DataTable.PropertyKeys.sortBy.toString());
        if (tableSortByVE != null) {
            groupByVE = tableSortByVE;
        }
        else {
            groupByVE = (table.getSortBy() == null || table.isMultiSort())
                        ? null
                        : context.getApplication().getExpressionFactory().createValueExpression(
                                eLContext, "#{" + table.getVar() + "." + table.getSortBy() + "}", Object.class);
        }

At a glance, I can't see how it was working without previously sorting if you look how the whole thing was/is implemented (it's an iterative process, so n + 1 item better be sorted otherwise you'll end up most likely having group of 1 element).

You can have a look also at PrimeNG, seems like they're doing the same

tandraschko commented 2 years ago

i just tried it with 8.0 and it wasnt sorted, but not idea if it was working

so lets close it as "works as expected"?

melloware commented 2 years ago

I say we close it as works as expected

halisyilboga commented 2 years ago

Aslinda grup satir yapmak ile sort yapmak arasinda fark var. Grup satirlamanin siralama olmadanda calisabilmesi gerekmektedir. We add newly added rows at the top of the table and this feature broke that. Also we make inplace edit and automatik sorting is also broke that feature. Last but not least default sorted column seems ugly and irritating. We can get the order from db or backend why I soppose to sort in filter. When I investigate SordOrder Enum I saw that it has a propertyv UNSORTED. But this feature is also does not work correct with grouprowing. This is definetly a bug.

jepsar commented 2 years ago

@halisyilboga please open a new issue which includes a reproducer and references this issue.