按下Tab键时会触发CellEdit事件

时间:2019-01-12 14:00:07

标签: javascript jsf primefaces datatable autofocus

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

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

我正在使用jsf 2.2和primefaces 6.1。

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

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

我尝试使用a:自动对焦,但也失败了。

 <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>

1 个答案:

答案 0 :(得分:0)

我在项目中开发了类似的东西。我的解决方案是禁用datatable单元格编辑,并根据需要仅将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>

我希望它会有所帮助:)