繁体   English   中英

如何更新primefaces dataTable中的特定单元格

[英]How update just specific cell in primefaces dataTable

我正在创建一个充满输入字段的动态数据表。 有时,当用户在某些输入中插入值时,应更新特定单元格,并且仅更新此单元格。 我认为这可能很简单,但却没有成功。 我要更新的单元格是“valor total”,当其他两个单元格的值发生变化时,应更新此单元格:

要更新的单元格

EDITED

js chrome

我试过f:带有完整id的ajax并得到“具有id的组件:lancamentoNF:popupLancamentoNF:tabelaItensNF:0:找不到valorTotalItem”。 更改为p:ajax并且没有错误发生但它没有更新!!

<h:panelGroup id="painelItensNF" layout="block" styleClass="hrgi-div-form aba-lancamento-nf clearfix" style="overflow:auto;">
    <h:panelGroup layout="block" style="width: 1700px;">
        <p:dataTable id="tabelaItensNF" value="#{modeloTabelaDinamicaItemNF.itens}" var="itemEmbrulhado" styleClass="tabelaDinamica" height="174" style="width: 100%;" rowIndexVar="indice">
            ... (some columns)
            <p:column style="width: 5%"
                      headerText="quantidade">
                <hrgi:spinner id="quantidadeItem"
                              value="#{itemEmbrulhado.item.produto.detalheTributavel.quantidade}"
                              dinheiro="false"
                              fator="#{itemEmbrulhado.item.produto.detalheTributavel.unidadeFracionada?0.01:1}"
                              local="pt-BR" min="0.00" width="70">
                    <p:ajax event="change"
                            update="lancamentoNF:popupLancamentoNF:tabelaItensNF:#{indice}:valorTotalItem"
                            listener="#{controladorPopupLancamentoNF.calcularValorTotalItem(itemEmbrulhado)}" global="false" />
                    <f:convertNumber
                            maxFractionDigits="#{itemEmbrulhado.item.produto.detalheTributavel.unidadeFracionada?2:0}"
                            minFractionDigits="#{itemEmbrulhado.item.produto.detalheTributavel.unidadeFracionada?2:0}"
                            locale="pt-BR"
                            for="quantidadeItem"/>
                </hrgi:spinner>
            </p:column>
            <p:column style="width: 5%"
                      headerText="valor unitario">
                <hrgi:spinner id="valorUnitarioItem"
                              value="#{itemEmbrulhado.item.produto.detalheTributavel.valorUnitario}"
                              dinheiro="true" fator="0.01" local="pt-BR" min="0.00" width="70">
                    <p:ajax event="change" 
                            update="lancamentoNF:popupLancamentoNF:tabelaItensNF:#{indice}:valorTotalItem"
                            listener="#{controladorPopupLancamentoNF.calcularValorTotalItem(itemEmbrulhado)}" global="false"/>
                    <f:convertNumber type="currency" currencyCode="BRL" currencySymbol="R$ "
                                     maxFractionDigits="10" minFractionDigits="2" locale="#{cc.attrs.local}"
                                     for="valorUnitarioItem"/>
                </hrgi:spinner>
            </p:column>
            <p:column style="width: 3%"
                      headerText="valor total">
                <h:outputText id="valorTotalItem" value="#{itemEmbrulhado.item.produto.valorTotal}">
                    <f:convertNumber type="currency" currencyCode="BRL" currencySymbol="R$ "
                                     maxFractionDigits="2" minFractionDigits="2" locale="pt-BR"
                                     for="valorUnitarioItem"/>
                </h:outputText>
            </p:column>
            ... (more columns)
        </p:dataTable>
    </h:panelGroup>
</h:panelGroup>

当我用完整的id更新panelGroup“painelItensNF”时,它可以正常工作,但焦点丢失了,用户应该找到他正在努力继续的输入...

只需使用update="valorTotalItem" 它已经相对于当前行。

所以,替换

<p:ajax ... update="lancamentoNF:popupLancamentoNF:tabelaItensNF:#{indice}:valorTotalItem" />

通过

<p:ajax ... update="valorTotalItem" />

我不认为更新单个单元格是可能的。 它的id是自动生成的,因此您无法通过id更新此组件。
您可以尝试切换到primefaces 3.3(尚未最终发布,但您可以开始使用快照),并尝试使用primefaces选择器执行您想要的操作: http//www.primefaces.org/showcase-labs/ UI / selectors.jsf
你会有更多的变化,但我不确定你是否能够做到这一点。

或者,您可以更新面板并添加一些javascript以将焦点设置为适当的组件。 在p:ajax组件的“oncomplete”方法中执行javascript。

编辑:从更新中删除索引,所以它看起来像这样:“:lancamentoNF:popupLancamentoNF:tabelaItensNF:valorTotalItem”当然BalusC是对的,你也可以只使用“valorTotalItem”

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM