简体   繁体   English

如何从primefaces数据表中删除/取消绑定rowSelect事件

[英]How to remove/unbind rowSelect event from primefaces datatable

My main problem is I want to remove/unbind rowSelect, rowUnselect and rowDblselect events 我的主要问题是我想删除/取消绑定rowSelect,rowUnselect和rowDblselect事件
from datatable. 来自数据表。

<p:dataTable id="myTable" value="#{myBean.myLazyModel}" var="var" 
        selection="#{myBean.selectedBean}" styleClass="uta-table lightgrey-table">

        <p:column selectionMode="multiple" id="select"
            style="width:2%;text-align:center" />

        <p:column id="namecol" headerText="Name" style="text-align:center">
            <p:inputText id="name" value="#{var.name}"
                styleClass="uta-textbox" style="text-align:center">
            </p:inputText>
        </p:column>
</p:dataTable>

Assume the datatable has only 5 rows. 假设数据表只有5行。 Now I have selected first 4 rows by selecting checkbox (not by clicking on row). 现在我通过选择复选框(而不是通过单击行)选择前4行。 If I select 5th row by clicking on the row(not selecting the checkbox) then the previous 4 rows are deselected resulting in only 5th row being selected. 如果我通过单击行选择第5行(不选中复选框),则取消选择前4行,导致仅选择第5行。 This is something concerns my client. 这是我的客户关注的问题。

To avoid this problem I thought of unbinding/removing rowSelect event means I should be able to select a row only by selecting checkbox. 为了避免这个问题我想到解除绑定/删除rowSelect事件意味着我应该只能通过选择复选框来选择一行。 This same problem persists in the primeface showcase also. 同样的问题也存在于主要展示中。

http://www.primefaces.org/showcase/ui/datatableRowSelectionRadioCheckbox.jsf http://www.primefaces.org/showcase/ui/datatableRowSelectionRadioCheckbox.jsf

I tried to unbind/remove rowSelect event in the following two ways using jQuery css selectors 我尝试使用jQuery css选择器以下面两种方式取消绑定/删除rowSelect事件

<script type="text/javascript">
            jQuery(function() {                        
                $('.lightgrey-table').off("rowSelect");
                $('.lightgrey-table').off("rowUnselect");
                $('.lightgrey-table').off("rowDblselect");

            });
</script>  

second way 第二种方式

<script type="text/javascript">
            jQuery(function() {                        
                $('.lightgrey-table').unbind("rowSelect");
                $('.lightgrey-table').unbind("rowUnselect");
                $('.lightgrey-table').unbind("rowDblselect");

            });
</script>  

both didn't work for me. 两者都不适合我。 Could any one help me to resolve this. 任何人都可以帮我解决这个问题。

thanks in advance guys 先谢谢你们

It's not obvious, but pressing the CTRL key will allow multiple rows to be selected without affecting already selected rows. 这并不明显,但按下CTRL键将允许选择多行而不影响已选择的行。

If the CTRL key option won't work for your client, you will need to turn the jQuery '$' shortcut back on to use it on a PrimeFaces app. 如果CTRL键选项对您的客户端不起作用,则需要重新启用jQuery'$'快捷方式以在PrimeFaces应用程序上使用它。 Include the following JSF outputScript tags: 包括以下JSF outputScript标记:

<h:outputScript library="primefaces" name="jquery/jquery.js" target="head" />

<h:outputScript target="head">
   $ = jQuery; // Put $ back so we can use jQuery in the default mode.
   $(document).ready(function() {
          // put your jQuery code here....
   });  </h:outputScript>

You can design your columns this way 您可以这样设计列

<p:datatable ...
   <p:column selectRow="false" ... />
</p:datatable>

In this way you can only select and unselect your rows by clicking on the checkbox. 这样,您只能通过单击复选框来选择和取消选择行。

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

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