【问题标题】:Disable selection in datatable禁用数据表中的选择
【发布时间】:2017-01-05 06:24:19
【问题描述】:

我使用的是 Primefaces 5.3,如果记录的长度低于 10 条,我会用数据库中的一些记录填充数据表,我用空记录完成它,因此数据表始终显示 10 行。

我的数据表如下所示:

<p:dataTable id="dataTable"
   editable="true" editMode="cell"
   value="#{beanPlanningl.getListPlanningSalle(entry, 1)}"
   var="planning"
   selectionMode="single"
   selection="#{beanPlanning.selectedPlanning}"
   rowKey="#{planning.id}"
   sortBy="#{planning.heureDebut}"
   >

所以我想要的是禁用对具有空记录的行的选择。

我该怎么做?

PS : planning.id 在空记录中等于 0。

编辑:

我忘了说我已经使用了rendered,如下:

<p:column >
  <p:cellEditor rendered="#{planning.id != 0}">
      <f:facet name="output"> <h:outputText value="#{planning.heureDebut}" /></f:facet>
      <f:facet name="input">
          <p:inputMask mask="99:99" value="#{planning.heureDebut}"
                       required="true" maxlength="4"
                       requiredMessage="Heure de début : vous devez indiquer une valeur."
                       validatorMessage="Heure de début non valide.">
              <f:validateRegex pattern="([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]"/>
          </p:inputMask>
      </f:facet>
  </p:cellEditor>
</p:column>

但这只会阻止编辑单元格,但它们始终可以被选中。

编辑 2:

在我使用disabledSelection 之前,我尝试使用disabledSelection 现在无法选择行,但始终可以选择单元格:

如您所见,我可以选择行并在悬停时显示颜色。

然后当我使用disabledSelection 时:

现在悬停不适用于空行和行上的选择,但始终可以选择单元格,所以不,我只需要防止这种情况发生。

I noticed that when the cell is selected two css classes are added : ui-state-highlight ui-cell-editing.

【问题讨论】:

  • 您是否尝试将rendred 添加到您的dataTable 中?!?
  • 如果你改变rendred条件值,rendered="#{YourManagedBean.yourCondition}"不要忘记更新dataTable
  • @YagamiLight 是的,否则我的单元格将是可编辑的,当我使用渲染时,我阻止编辑单元格,但我仍然可以选择它们。
  • @YagamiLight 请检查我的编辑
  • 你试过disabledSelection ?!?

标签: jsf jsf-2 primefaces jsf-2.2


【解决方案1】:

我所做的解决方案是防止其子级中没有.ui-cell-editor 的列的默认行为如下:

$(".ui-editable-column").click(function(event){
                    if(!$(this).find('.ui-cell-editor').length){
                        event.preventDefault();
                        return false;   
                    }
            });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-01
    • 2013-03-14
    • 1970-01-01
    • 1970-01-01
    • 2017-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多