Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #11885 - DataTable: Select/unselect all with selectionPageOnly="false" does not work properly #11911

Merged
merged 3 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@
</p:dataTable>

<p:commandButton id="button" value="Submit" update="@form" action="#{dataTable006.submit}"/>
<p:commandButton id="toggleSelectPageOnly" value="Selection Page Only" update="@form" action="#{dataTable006.toggleSelectPageOnly}"/>
<p:selectBooleanButton id="toggleSelectPageOnly" value="#{dataTable006.selectionPageOnly}"
onLabel="Page only" offLabel="All pages">
<p:ajax update="@form"/>
</p:selectBooleanButton>
<p:commandButton id="toggleLazyMode" value="Lazy Mode" update="@form" action="#{dataTable006.toggleLazyMode}"/>
<p:commandButton id="togglePaginator" value="Paginator" update="@form" action="#{dataTable006.togglePaginator}"/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
*/
package org.primefaces.integrationtests.datatable;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.json.JSONObject;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Order;
Expand All @@ -37,9 +34,13 @@
import org.primefaces.selenium.component.CommandButton;
import org.primefaces.selenium.component.DataTable;
import org.primefaces.selenium.component.Messages;
import org.primefaces.selenium.component.SelectBooleanButton;
import org.primefaces.selenium.component.model.Msg;
import org.primefaces.selenium.component.model.datatable.Row;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

class DataTable006Test extends AbstractDataTableTest {

@Test
Expand Down Expand Up @@ -338,6 +339,32 @@ void lazySelectionWithFiltering(Page page) {
assertConfiguration(dataTable.getWidgetConfiguration(), true);
}

@Test
@Order(9)
@DisplayName("DataTable: selection - unselect all for page with selectionPageOnly='false'")
void unselectAllRows(Page page) {
// Arrange
DataTable dataTable = page.dataTable;

// Act - select all items on all pages
page.toggleSelectPageOnly.click();
dataTable.toggleSelectAllCheckBox();
page.submit.click();

// Assert
assertSelectAllCheckbox(dataTable, true);
assertSelections(page.messages, "1,2,3,4,5");

// Act - unselect all
dataTable.toggleSelectAllCheckBox();
page.submit.click();

// Assert
assertSelections(page.messages, "");
assertSelectAllCheckbox(dataTable, false);
assertConfiguration(dataTable.getWidgetConfiguration(), false);
}

private void assertConfiguration(JSONObject cfg, boolean selectionPageOnly) {
assertNoJavascriptErrors();
System.out.println("DataTable Config = " + cfg);
Expand Down Expand Up @@ -372,7 +399,7 @@ public static class Page extends AbstractPrimePage {
CommandButton buttonUnselect;

@FindBy(id = "form:toggleSelectPageOnly")
CommandButton toggleSelectPageOnly;
SelectBooleanButton toggleSelectPageOnly;

@FindBy(id = "form:toggleLazyMode")
CommandButton toggleLazyMode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2980,7 +2980,6 @@ PrimeFaces.widget.DataTable = PrimeFaces.widget.DeferredWidget.extend({
else {
this.checkAllToggler.addClass('ui-state-active').children('span.ui-chkbox-icon').removeClass('ui-icon-blank').addClass('ui-icon-check');
this.checkAllToggler.attr('aria-checked', true);


checkboxes.each(function() {
$this.selectRowWithCheckbox($(this), null, true);
Expand All @@ -2991,8 +2990,13 @@ PrimeFaces.widget.DataTable = PrimeFaces.widget.DeferredWidget.extend({
this.configureSelectAllAria();

// GitHub #6730 user wants all rows not just displayed rows
if(!this.cfg.selectionPageOnly && shouldCheckAll) {
this.selectAllRows();
if(!this.cfg.selectionPageOnly) {
if (shouldCheckAll) {
this.selectAllRows();
}
else {
this.unselectAllRows();
}
}

//save state
Expand Down