【问题标题】:CellEdit event fires when press tab button按下选项卡按钮时触发 CellEdit 事件
【发布时间】:2019-06-07 04:29:55
【问题描述】:

我的问题是,当我在编辑 datatable 时按下 tab 按钮时,datatable 的单元格被关闭并且 CellEdit 事件越来越多地触发。 它迫使我在屏幕上按左键单击任何商品以防止触发单元格编辑事件。

在单元格方法上,我做了一些计算以显示在页脚中。 所以它失去了光标焦点。

我正在使用 jsf 2.2 和 primefaces 6.1。

我的目标是当我编辑数量、进行计算并更新页脚行、总计和净列时,然后按标签光标出现在价格单元格中

我尝试只更新 p:columnGroup 页脚但失败了。

我尝试使用 a:autofocus 但也失败了。

 <p:remoteCommand name="onCellEdit" update="invInventoryTable" />
 <p:dataTable  var="invInventoryTable"
   widgetVar="invInventoryTable"
   rowIndexVar="index" 
   rowKey="#{invInventoryTable}"
   selectionMode="single"
   selection="#{invPurchaseOrderFormMB.invPurchaseOrderDetailEntitySelection}"
   dir="rtl" 
   emptyMessage="#{userData.userDDs['EMPTY_TABLE']}"
   editable="true"
   editMode="cell"
   value="#{invPurchaseOrderFormMB.invPurchaseOrderEntity.invPurchaseOrderDetailEntityList}"
   id="invInventoryTable">
     <p:ajax event="cellEdit" listener="#{invPurchaseOrderFormMB.onCellEdit}" oncomplete="onCellEdit()"/>

     <p:column style="width:7vh;font-size:1.6vh;text-align: right" a:autofocus="#{invPurchaseOrderFormMB.focus}" id="Quantity" headerText="QUANTITY">
         <p:cellEditor>
             <f:facet name="output">
                 <h:outputText value="#{invInventoryTable.quantity}"  />
             </f:facet>
             <f:facet name="input">
                 <p:inputText id="QuantityT" a:autofocus="#{invPurchaseOrderFormMB.focus}" value="#{invInventoryTable.quantity}"  style="width:90%"/>
             </f:facet>
         </p:cellEditor>                        
     </p:column>

     <p:column style="width:7vh;font-size:1.6vh;text-align: right" id="Price" headerText="PRICE">
         <p:cellEditor>
             <f:facet name="output">
                 <h:outputText  value="#{invInventoryTable.price}"  />
             </f:facet>
             <f:facet name="input">
                 <p:inputText id="PriceT" value="#{invInventoryTable.price}"  style="width:100%"/>
             </f:facet>
         </p:cellEditor>                        
     </p:column>

     <p:column style="width:7vh;font-size:1.6vh;text-align: right" id="Discount" headerText="DISCOUNT">
         <p:cellEditor>
             <f:facet name="output">
                 <h:outputText value="#{invInventoryTable.discountRate}"/>
             </f:facet>
             <f:facet name="input">
                 <p:inputText id="DiscountT" value="#{invInventoryTable.discountRate}"  style="width:100%">
                 </p:inputText>
             </f:facet>
         </p:cellEditor>                        
     </p:column>

     <p:column style="width:7vh;font-size:1.6vh;text-align: right"  id="total" headerText="TOTAL">
         <h:outputLabel id="totalVal" value="#{invInventoryTable.total}"  />
     </p:column>

     <p:column style="width:7vh;font-size:1.6vh;text-align: right" id="NET" headerText="NET">
         <h:outputLabel id="netVal" value="#{invInventoryTable.net}"  />
     </p:column>

     <p:columnGroup type="footer">
         <p:row>
             <p:column colspan="4" style="text-align:right" footerText="TOTAL  :" />
             <p:column id="qtyId" footerText="#{invPurchaseOrderFormMB.totalQuatity}" />
             <p:column/>
             <p:column/>
             <p:column id="totId" footerText="$#{invPurchaseOrderFormMB.total}" />
             <p:column id="totNetId" footerText="$#{invPurchaseOrderFormMB.totalNet}" />
             <p:column/>
             <p:column/>
             <p:column/>
             <p:column/>
             <p:column/>
         </p:row>
     </p:columnGroup>

 </p:dataTable>

【问题讨论】:

    标签: javascript jsf primefaces datatable autofocus


    【解决方案1】:

    我在我的项目中开发了类似的东西。我的解决方案是禁用数据表单元格编辑并根据需要仅对数量单元格使用 ajax:

    <p:dataTable  var="invInventoryTable"
                                  widgetVar="invInventoryTable"
                                  rowIndexVar="index" 
                                  rowKey="#{invInventoryTable}"
                                  selectionMode="single"
                                  selection="#{invPurchaseOrderFormMB.invPurchaseOrderDetailEntitySelection}"
                                  dir="rtl" 
                                  emptyMessage="#{userData.userDDs['EMPTY_TABLE']}"
                                  editable="true"
                                  editMode="cell"
                                  value="#{invPurchaseOrderFormMB.invPurchaseOrderEntity.invPurchaseOrderDetailEntityList}"
                                  id="invInventoryTable">
    
    
                        <p:ajax event="cellEdit" onstart="return false;" process="@this"/>
    
    
    
                        <p:column style="width:7vh;font-size:1.6vh;text-align: right" a:autofocus="#{invPurchaseOrderFormMB.focus}" id="Quantity" headerText="QUANTITY">
                            <p:cellEditor>
                                <f:facet name="output">
                                    <h:outputText value="#{invInventoryTable.quantity}"  />
                                </f:facet>
    
                                <f:facet name="input">
                                    <p:inputText id="QuantityT" a:autofocus="#{invPurchaseOrderFormMB.focus}" 
                  onkeydown="if(event.keyCode != 9 &amp;&amp; event.keyCode != 13){onkeydown();
               value="#{invInventoryTable.quantity}"  style="width:90%"
    
                                 <p:ajax event="keydown" listener="#{invPurchaseOrderFormMB.onCellEdit}" update=""/>           
                                  </p:inputText>
                                </f:facet>
                            </p:cellEditor>                        
                        </p:column>
    

    希望对你有帮助:)

    【讨论】:

    • 我通过删除 oncomplete="onCellEdit()" 解决了这个问题,并为每一列分别添加了 ajax 像这样
    • 非常感谢。 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-03
    • 2013-10-11
    • 2011-02-06
    • 1970-01-01
    • 1970-01-01
    • 2016-02-08
    • 2012-08-17
    相关资源
    最近更新 更多