简体   繁体   English

按下Tab键时会触发CellEdit事件

[英]CellEdit event fires when press tab button

My problem is that when I press tab button while editing datatable , cells of datatable are closed and CellEdit event fires more and more. 我的问题是,当我在编辑datatable时按下tab键时,datatable的单元格被关闭,并且CellEdit事件越来越多地触发。 It force me to press left click any ware in the screen to prevent firing cell edit event. 它迫使我在屏幕上单击左键单击任何软件,以防止触发单元格编辑事件。

on cell method I do some calculations to appear in footer. 关于单元格方法,我做了一些计算以显示在页脚中。 So it loses cursor focus. 因此,它失去了光标焦点。

I am using jsf 2.2 and primefaces 6.1. 我正在使用jsf 2.2和primefaces 6.1。

My goal is when I edit on quantity, do my calculations and update footer row and total and net columns, then press tab cursor appear in price cell 我的目标是编辑数量,进行计算并更新页脚行以及总计和净列,然后按Tab光标出现在价格单元中

I've tried to just update only p:columnGroup footer but failed. 我试图只更新p:columnGroup页脚,但失败了。

I tried to use a:autofocus but also fails. 我尝试使用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>

I had develop something like this in my project . 我在项目中开发了类似的东西。 my solution is to disable datatable cell edit and use ajax just for the quantity cell as i want : 我的解决方案是禁用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>

i hope it helps :) 我希望它会有所帮助:)

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

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