Disable row selection for only a few rows.

I would like to know if there is a way to disable radio-based row selection for a given set of strings in Primefaces based on the bean property.

Example:

<p:dataTable var="foo" value="#{bean.foos}" selection="#{bean.selectedFoo}">` <p:column selectionMode="single" />` <p:column> <h:outputText value="#{foo.bar}" /> </p:column> <p:dataTable 

In this case, imagine that I would like to disable the lines where foo.bar == 1,5,10 , by disabling the lines that I mean, turn off the switch associated with the line.

I could not figure out how to do this ... any ideas? Even a css + javascript hack solution would be acceptable.

Thanks!

+6
source share
4 answers

Check this link for a way to disable row select checkboxes . The only difference is that in your case this is the only choice, but this does not affect this decision.

+2
source

Starting with version 5.0, Primables datatable comes with the disabledSelection property.

 <p:dataTable var="foo" value="#{bean.foos}" selection="#{bean.selectedFoo}" disabledSelection="#{foo.bar == 1}"> <p:column selectionMode="single" /> <p:column> <h:outputText value="#{foo.bar}" /> </p:column> <p:dataTable> 

Then, when foo.bar == 1 true, the checkbox will be disabled.

+4
source

You can try disabling jquery as follows

 <script type="text/javascript" src="jquery.js"></script> <script> $(function(){ $("#myform input[type = radio]:nth(1)").attr('disabled', 'disabled'); }); </script> 

myform: your form name In place of the nth (1), you can specify the line number to be rejected.

0
source

I ran into the same problem when I wanted to disable only certain lines from the selection (one or more) based on the bean property. The short answer for me was simply to hide the radio / checkbox on this line so that it could not be selected. My needs required that I be able to handle additional options at runtime. This meant that I had to be sure that the rows were not physically selected before any additional choices were made so that they were not reprocessed in subsequent processing, so do not forget about this condition.

Here is what I have done, for others who may stumble upon this question in the future.

1) In p: datatable, I added the rowStyleClass attribute and based on the bean criteria, providing a class, for example: 'select-selectable' or 'not-selectable'.

 rowStyleClass="#{myBean.alreadyProcessedList.contains(item) ? 'not-selectable' : 'is-selectable'}" 

In my execution process, the selected rows were added to this list, so they would be made "not selectable" after the form was displayed again after processing. Your initial load should contain unselectable lines that are already added to the list, or handle any condition that you need in your case.

2) Define CSS to make .not-selectable hide the radio / flag. Using "! Important" was necessary to override the inline style.

 tr.not-selectable div.ui-radiobutton, tr.not-selectable div.ui-chkbox { visibility: hidden !important; } 
0
source

Source: https://habr.com/ru/post/890813/


All Articles