如何仅更新primefaces dataTable 中的特定单元格 [英] How update just specific cell in primefaces dataTable
问题描述
我正在创建一个充满输入字段的动态数据表.有时,当用户在某些输入中插入值时,应更新特定单元格,并且仅更新此单元格.我认为这可能很简单,但并没有让它发挥作用.我要更新的单元格是valor total",当其他两个单元格的值发生变化时,应更新此单元格:
I'm creating a dynamic datatable full of input fields. Sometimes when user insert values in some inputs, an specific cell should be updated, and only this cell. I thought it could be simple, but yet didn't make it work. The cell I want update is "valor total", this cell should be updated when the value of two others cell change:
已编辑
我尝试了具有完整 id 的 f:ajax 并得到未找到具有 id:lancamentoNF:popupLancamentoNF:tabelaItensNF:0:valorTotalItem 的组件".改成 p:ajax 没有报错但是没有更新!!
I've tryied f:ajax with complete id and got "Component with id:lancamentoNF:popupLancamentoNF:tabelaItensNF:0:valorTotalItem not found". Changed to p:ajax and no errors happen but it doesn't update!!
<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" 时它可以工作,但是焦点丢失了,用户应该找到他正在工作的输入以继续......
It works when I update the panelGroup "painelItensNF" with complete id, but the focus is lost and user should find the input he was working to continue...
推荐答案
只需使用 update="valorTotalItem"
.它已经相对于当前行.
Just use update="valorTotalItem"
. It's relative to the current row already.
所以,替换
<p:ajax ... update="lancamentoNF:popupLancamentoNF:tabelaItensNF:#{indice}:valorTotalItem" />
由
<p:ajax ... update="valorTotalItem" />
这篇关于如何仅更新primefaces dataTable 中的特定单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!