简体   繁体   English

如何在primefaces中禁用数据表的行选择

[英]how to disable row-selection of datatable in primefaces

I am using Primefaces 4.0, I am having a datatable with multiple selection features.What Im willing to achieve is to select the rows only by the checkbox button, disabling capability of clicking a row. 我正在使用Primefaces 4.0,我有一个具有多个选择功能的数据表。我愿意实现的是仅通过复选框按钮选择行,禁用单击行的功能。 IN present scenario my checkbox is selected even if i click on any row, I want to disable row-selected. 在目前的情况下我的复选框被选中,即使我点击任何一行,我想禁用行选择。

<p:dataTable id="tradingTable" scrollable="true"
                resizableColumns="true" draggableColumns="true"  scrollWidth="1265"
                scrollHeight="650" var="pgers"
                selection="#{pager.selectedPageArray}"
                value="#{pager.pageDataModel}"
                sortMode="multiple"
                editable="true" editMode="cell" 
                rowSelectMode="add"     

                >  
                <p:column width="30" selectionMode="multiple"   >
                </p:column> 

I got some solution from this forum but unable to resolved it. 我从这个论坛得到了一些解决方案,但无法解决。 Please suggest me what needed to be done. 请建议我需要做什么。

Although your question is about Primefaces 4.0, I thought it would be useful to highlight that this problem is now solved in newer versions. 虽然你的问题是关于Primefaces 4.0的,但我认为强调现在这个问题在新版本中得到解决是有用的。 It may be useful to someone else. 它可能对其他人有用。

According to this feature request , this feature is now supported in Primefaces versions 5.0.3 & 5.1 by simply adding rowSelectMode="checkbox" to the datatable. 根据此功能请求 ,Primefaces版本5.0.35.1现在支持此功能,只需将rowSelectMode =“checkbox”添加到数据表即可。

Documentation reference (PF 5.1): 文档参考(PF 5.1):

Use rowSelectMode option to customize the default behavior on row click of a multiple selection enabled datatable. 使用rowSelectMode选项可以自定义启用多选的数据表的行单击时的默认行为。 Default value is "new" that clears previous selections, "add" mode keeps previous selections same as selecting a row with mouse click when metakey is on and "checkbox" mode allows row selection with checkboxes only. 默认值为“new”,用于清除先前的选择,“add”模式保持以前的选择与在metakey打开时用鼠标单击选择行相同,“checkbox”模式允许仅选择复选框的行选择。

I'm using PrimeFaces 3.5, but I think the same workaround should be applicable. 我正在使用PrimeFaces 3.5,但我认为同样的解决方法应该适用。
What I did to disable the row selection is to remove the selected row immediately with the rowSelect event by adding <p:ajax /> component in the datatable . 我禁用行选择的方法是通过在数据表中添加<p:ajax />组件,立即使用rowSelect事件删除所选行

It might not a good solution, but at least it works. 它可能不是一个好的解决方案,但至少它是有效的。

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

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