0
votes

I have a dataTable something like the code above, as you can see, im using the event rowSelectedcheckBox, there is any way to know the row that was clicked and based on that information disabled the row completely?

 <p:dataTable id="tblTipoCarteraGeneric" style="text-align:left;" 
                     value="#{alertasPredefinidasModel.tipoCarteraDTOs}"
                     var="tipoCartera"
                     rows="15" paginator="true"
                     emptyMessage="empty"
                     paginatorAlwaysVisible="true" 
                     paginatorPosition="bottom"                         
                     selection="#{alertasPredefinidasModel.elementoSeleccionado.tipoCarteraDTOs}"
                     rowKey="#{tipoCartera.tipoCarteraDTO.tipocarteraID}"
                     rendered="#{alertasPredefinidasModel.isTipoCartera()}">

            <p:ajax event="rowSelectCheckbox" update=":form:tblTipoCarteraGeneric, :form:messages" 
                    listener="#{alertasPredefinidasController.onRowSelected}"/>
            <p:ajax event="rowUnselectCheckbox" update=":form:tblTipoCarteraGeneric, :form:messages" 
                    listener="#{alertasPredefinidasController.onRowUnselected}"/>

            <p:column selectionMode="multiple" styleClass="selection-column no-all"
                      disabledSelection="#{alertasPredefinidasModel.modoDetalle}"/>

            <p:column headerText="Tipo de cartera" styleClass="wrappedText" >
                <h:outputText id="inTxtCol1" value="#{tipoCartera.tipoCarteraDTO.nombre}" />
            </p:column>
            <p:column headerText="Valor del abono" styleClass="wrappedText" rendered="#{alertasPredefinidasModel.isTipoCarteraConValorOpcion2()}">
                <h:inputText id="inTxtCol2" value="#{tipoCartera.parametro1}" style="width:100%" 
                             disabled="#{alertasPredefinidasModel.modoDetalle}"/>
                <pe:tooltip myPosition="top center" atPosition="bottom right" for="inTxtCol2"                                       
                            value="#{tooltips.obtainToolTip('parametrizarAlertasPredefinidas', 'inTxtCol2', 'es', 'itac.SIT-Core-Middleware-Sarlaft-WAR.tooltip')} "/>
            </p:column>
            <p:column headerText="Porcentaje superior al valor del abono" styleClass="wrappedText" rendered="#{alertasPredefinidasModel.isTipoCarteraConValorOpcion2()}">
                <h:inputText id="inTxtCol3" value="#{tipoCartera.parametro2}" style="width:100%" 
                             disabled="#{alertasPredefinidasModel.modoDetalle}"/>
                <pe:tooltip myPosition="top center" atPosition="bottom right" for="inTxtCol3"                                       
                            value="#{tooltips.obtainToolTip('parametrizarAlertasPredefinidas', 'inTxtCol3', 'es', 'itac.SIT-Core-Middleware-Sarlaft-WAR.tooltip')} "/>
            </p:column>
        </p:dataTable>
2
What you want ? Do you want to disable selected row/ rows? Once you disable a row , you can't enable that row/rows. Is this your requirement?Diganta
Just like a "toggle" (when checked, will activate the input Text; when not, will be deactivated)Sergio

2 Answers

1
votes

I think this will fulfill your requirement. I add one extra attribute styleClass="tblTipoCarteraGeneric" to your <p:dataTable> and add two <p:ajax> with events page(because after page change to keep previous page's user interaction record as same) and toggleSelect(if user select header checkbox instead of using singe chek box of each row).

Suppose if your <p:dataTable> is wrapped like this :

<h:form>
<p:dataTable id="tblTipoCarteraGeneric" styleClass="tblTipoCarteraGeneric" ......>
    <p:ajax event="rowSelectCheckbox" oncomplete="abcd()" />
    <p:ajax event="page" oncomplete="abcd()" />
    <p:ajax event="toggleSelect" oncomplete="abcd()" />

    <p:column></p:column>
    ..
    ..
    ..
    <p:column></p:column>
</p:dataTable>
<h:outputScript>var abcd = function(){

    $('div.tblTipoCarteraGeneric >div > table > tbody > tr').each(function(){
        if($(this).hasClass('ui-state-highlight')){
            $(this).css({'pointer-events': 'none'});
        } else {
        $(this).css({'pointer-events': 'auto'});
        }
    });
    };
</h:outputScript>
</form>
-1
votes

You can use rowIndex attribute of Datatable. You can use rowIndex in StyleClass and bind on click call a javascript method. Get the row through its class which will have rowIndex.

You Can also refer this

Primefaces example