question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Datatable: Lazy Sorting Regression

See original GitHub issue

Describe the defect After the new sorting was implemented in https://github.com/primefaces/primefaces/issues/5438 one of the Integration Test Cases is now failing.

Error DataTable002Test.testLazyFilter:151 expected: <Language 18> but was: <Language 9>

Reproducer Integration Test: https://github.com/primefaces-extensions/primefaces-integration-tests/blob/dc72818c1e099191b6e47bf2b9e46ab85801de54/src/test/java/org/primefaces/extensions/integrationtests/datatable/DataTable002Test.java#L126-L154

Environment:

  • PF Version: 9.0

Example XHTML

<h:form id="frmTest">
<p:dataTable id="datatable" value="#{dataTable002.lazyDataModel}" var="lang" paginator="true" rows="10" filteredValue="#{dataTable002.filteredProgLanguages}" lazy="true">
           <p:column headerText="ID" sortBy="#{lang.id}">
                <h:outputText value="#{lang.id}" />
            </p:column>

            <p:column headerText="Name" sortBy="#{lang.name}" filterBy="#{lang.name}" filterMatchMode="contains">
                    <h:outputText value="#{lang.name}" />
            </p:column>

            <p:column headerText="First appeared" sortBy="#{lang.firstAppeared}" filterBy="#{lang.firstAppeared}" filterMatchMode="gte">
                    <h:outputText value="#{lang.firstAppeared}" />
            </p:column>
</p:dataTable>
</h:form>

Integration Test

    @Test
    @Order(3)
    @DisplayName("DataTable: Lazy: filter")
    public void testLazyFilter(Page page) {
        // Arrange
        DataTable dataTable = page.dataTable;
        Assertions.assertNotNull(dataTable);
        List<ProgrammingLanguage> langsFiltered = langs.getLangs().stream()
                .filter(l -> l.getFirstAppeared() >= 1998)
                .sorted(Comparator.comparingInt(ProgrammingLanguage::getFirstAppeared))
                .collect(Collectors.toList());

        // Act
        dataTable.selectPage(1);
        dataTable.sort("First appeared");
        dataTable.filter("First appeared", "1998");

        // Assert
        List<Row> rows = dataTable.getRows();
        Assertions.assertNotNull(rows);
        Assertions.assertEquals(10, rows.size()); //one page

        Assertions.assertEquals(langsFiltered.get(0).getName(), rows.get(0).getCell(1).getText());
        Assertions.assertEquals(langsFiltered.get(1).getName(), rows.get(1).getCell(1).getText()); //fails

        assertConfiguration(dataTable.getWidgetConfiguration());
    }

We sort by First Appeared year and you can see its sorted correctly: image

Then we filter by year 1998 and the filtering works but the list is now unsorted with 1998 and 1999 mixed together even though the column is sorted. So our test fails because record #2 should not be 1999 it should be another 1998 DataTable002Test.testLazyFilter:151 expected: <Language 18> but was: <Language 9> It appears to be sorted by the Id column now again.

image

@christophs78 @Rapster

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:23 (23 by maintainers)

github_iconTop GitHub Comments

1reaction
tandraschkocommented, Nov 8, 2020

i will get a beer now and explain when state/fields etc. are used 😃

0reactions
mellowarecommented, Nov 9, 2020

@Rapster thank you I can confirm all the Integration Tests are now passing including all of the tests that were added to prove you have fixed the other sorting defects! https://github.com/primefaces-extensions/primefaces-integration-tests/actions/runs/352863652

Read more comments on GitHub >

github_iconTop Results From Across the Web

DataTable Lazy Data Loading with Pagination and Sorting
We are going to use JPA, Hibernate and in-memory H2 database to persist/load data.
Read more >
jsf - Sorting parameters not passed correctly to a lazy loading ...
I'm trying to implement lazy loading in an ace:dataTable. My web application has quite a lot of tables, so I've tried to reduce...
Read more >
DataTable Lazy loading with Sorting and filtering
I've a lazy loading datatable with sorting and filtering. All data is being loaded successfully but when I sort on second page the...
Read more >
primefaces - issue #1363 - Google Code
I try to format my columns in a p:dataTable. My Target is to align the columns with numbers to the right. Example 1:...
Read more >
column index dplyr
Sorting with sort_index() 09-Oct-2016 I'm trying to return the column with ... dplyr ( data. table Package Video, Further Resources & Summary Here's...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found