[英]How update just specific cell in primefaces dataTable
我正在創建一個充滿輸入字段的動態數據表。 有時,當用戶在某些輸入中插入值時,應更新特定單元格,並且僅更新此單元格。 我認為這可能很簡單,但卻沒有成功。 我要更新的單元格是“valor total”,當其他兩個單元格的值發生變化時,應更新此單元格:
EDITED
我試過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.