2010-11-01 4 views
1

Je donne les résultats suivants datable:richfaces datatable et sous-table

<rich:dataTable id="grid1" value="#{monitorForm.customerList}" var="custRow"> 
<rich:column width="5"> 
    <h:selectBooleanCheckbox value="#{custRow.selected}"> 
    <a:support event="onclick" action="#{monitorForm.selectOrderLines(custRow)}" 
     reRender="custTable_#{custRow.id}"/> 
    </h:selectBooleanCheckbox> 
</rich:column> 

<rich:subTable id="custTable_#{custRow.id}" 
     var="row" value="#{custRow.orderList}" rendered="#{custRow.show}"> 
<rich:column width="5"> 
<h:selectBooleanCheckbox value="#{row.checked}" /> 
</rich:column> 

    <rich:column> 
<h:outputText value="#{row.name}" /> 
</rich:column> 
</rich:subTable> 

</rich:dataTable> 

Lorsque je clique sur la case à cocher l'action #{monitorForm.selectOrderLines(custRow)} définit les cases à cocher pour le client sélectionné et je veux que la sous-table pour ce client à nouveau rendu. Ce qui précède ne fonctionne pas. L'erreur est n'existe pas.

Tout fonctionne très bien quand j'utilise reRender="grid1" mais cela peut être très lent quand il y a beaucoup de lignes.

Est-il possible d'avoir rich:subTable avec un ID dynamique que je peux utiliser pour ré-indiquer uniquement ce sous-tableau?

Répondre

0

Une solution que je utilise est maintenant:

<rich:dataTable id="grid1" value="#{monitorForm.customerList}"> 
    <rich:column width="5"> 
    <h:selectBooleanCheckbox value="" onclick="selectAllPackingLists(this, '#{custRow.id}')"/> 
    </rich:column> 

<rich:subTable var="row" value="#{custRow.orderList}" rendered="#{custRow.show}"> 
    <rich:column> 
     <input type='hidden' value='#{custRow.id}'/> 
    </rich:column> 

<rich:column width="5"> 
<h:selectBooleanCheckbox value="#{row.checked}" /> 
</rich:column> 

</rich:subTable> 

</rich:dataTable> 

fonction javascript:

   function selectAllPackingLists(o, id) { 
        var elem = jQuery("table[id='monitorFrm:grid1'] > tbody"); 
        var checked = o.checked; 

        var rows = elem.attr('rows'); 

        jQuery.each(rows, function(index, row) { 
          // for each row check if the input value in 1st column 
          // matches the selected customer id 
         var td = jQuery('td:first', this); 
         var hiddenFld = jQuery('input:first', td); 

         if (hiddenFld.val() == id) { 
            // set the checkbox in the 2nd column to true 
          var td2 = jQuery('td:nth-child(2)', this); 
          var cb = jQuery('input:first', td2); 

          jQuery(cb).attr('checked', checked); 
         } 
        }); 
       } 

Ce qui est formidable est que le réglage des cases à cocher via JQuery définit également les valeurs du haricot pour chaque <h:selectBooleanCheckbox value="#{row.checked}" /> correspondant

Je ne savais pas que cela ferait l'affaire.

0

Pourriez-vous essayer de définir le sous-tableau id="custTable" et faire reRender="custTable" et voir si cela fonctionne pour vous.

+0

Salut, il peut y avoir plusieurs sous-tables en fonction du nombre de clients, donc 1 identifiant pour tous ne fonctionnerait pas. Aussi j'ai lu que l'identification ne peut pas être réglée dynamiquement. Il y a une bonne réponse sur http://stackoverflow.com/questions/316790/dynamic-ids-in-jsf-seam – Guus