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: Enable row selection per button even if disabledSelection="true"

See original GitHub issue

Description

When we worked with PrimeFaces 8.0 it was possible to set disabledSelection=“true” on a p:dataTable so that the selection of a row was only possible by clicking on a designated button. With PrimeFaces 10.0 this was not possible anymore because if disabledSelection=“true” was set, no rows were highlighted anymore, despite the current selection. So we could use that feature only with a nasty workaround.

Describe the solution you would like

I think the use case for this is still valid, and maybe it can be re-enabled. I will attach a PR. Let me know what you think about it.

Additional context

For example, I use the dataTable as follow: <p:dataTable var="car" value="#{dtBasicView.cars}" multiViewState="true" rowKey="#{car.number}" selection="#{dtBasicView.selectedCar}" selectionMode="single" disabledSelection="true" rows="60" paginator="true" lazy="false"

Important is disabledSelection=“true” so that the user can not select rows per click on a row or cell. It should only be possible with a click on a button that is included in every row.

That is made with a column that include a button like this: <p:column headerText="Action" width="80"> <p:commandButton value="Select" update="@all" process="@this"> <f:setPropertyActionListener value="#{car}" target="#{dtBasicView.selectedCar}" /> </p:commandButton> </p:column>

That is like an example which is shown in the PrimeFaces documentation. So with PrimeFaces 10 I can select the row with that button, but the selected row is not highlighted as it should, which worked with PrimeFaces 8 (I also checked PF11 and the latest code base).

So my changes make that in that case the selected row is now highlighted.

I hope this will help to understand why I need that change. If you need more information, I will be happy to provide some.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:25 (25 by maintainers)

github_iconTop GitHub Comments

2reactions
Rapstercommented, Jun 18, 2022

Do this instead:

        <p:dataTable var="car" value="#{dtBasicView.cars}"
                     rows="60" paginator="true"
                     rowKey="#{car.number}" selection="#{dtBasicView.selectedCar}"
                     selectionMode="single" disabledSelection="#{!car.selected}">

            <p:column headerText="Action" width="80">
                <p:commandButton value="Select" update="@form" process="@form" action="#{dtBasicView.setSelected(car)}"/>
            </p:column>

            <p:column field="number"/>

            <p:column field="name"/>

        </p:dataTable>

And add this method in your bean:

public void setSelected(Car car) {
        selectedCar = car;
        car.setSelected(true);
       // reset selected for others
}

I wonder if you really need to enable selection feature, maybe you should stick to your custom selection and forget what PF can do for you. It’s most probably simpler that way

Out of scope, but avoid @all unless it’s really really necessary

1reaction
marw1ttcommented, Jun 23, 2022

Hi there, I just wanted to let you know, that I am on holiday for three weeks starting this weekend. There I have almost no internet access, so if you need something from me, I can only take care of it afterwards. So do not wonder if I do not reply to anything.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Enable button on row select — DataTables forums
I'm trying to use the select event but can't get it to fire. Be great if you could take a look at my...
Read more >
Data table component - Vuetify
The v-data-table component is used for displaying tabular data. Features include sorting, searching, pagination, content-editing, and row selection.
Read more >
DataTable 1.10 - Disable row select event for certain columns
However , if the first column i used for sliding child row display, I would like to avoid the row selection ( this...
Read more >
data table component - Carbon Design System
This variant of table enables the user to select individual rows and apply an action. A batch action toolbar appears when table rows...
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