禁用数据表中的选择
Disable selection in datatable
我正在使用 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}"
>
所以我想要的是在具有空记录的行上禁用 selection。
我该怎么做?
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>
但这只会阻止编辑单元格,但它们始终可以被 select编辑。
编辑 2:
我尝试使用 disabledSelection
现在我不能 select 行但是单元格总是可以 selected,在我使用 disabledSelection
之前:
如您所见,我可以 select 行,悬停时它们会变色。
然后当我使用 disabledSelection
时:
现在悬停对空行不起作用,select离子对行也不起作用,但单元格始终可以 selected,所以不,我只需要防止它发生。
我注意到当单元格被 selected 时添加了两个 css 类 :ui-state-highlight ui-cell-editing
.
我所做的解决方案是防止其子项中没有 .ui-cell-editor
的列的默认行为如下:
$(".ui-editable-column").click(function(event){
if(!$(this).find('.ui-cell-editor').length){
event.preventDefault();
return false;
}
});
我正在使用 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}"
>
所以我想要的是在具有空记录的行上禁用 selection。
我该怎么做?
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>
但这只会阻止编辑单元格,但它们始终可以被 select编辑。
编辑 2:
我尝试使用 disabledSelection
现在我不能 select 行但是单元格总是可以 selected,在我使用 disabledSelection
之前:
如您所见,我可以 select 行,悬停时它们会变色。
然后当我使用 disabledSelection
时:
现在悬停对空行不起作用,select离子对行也不起作用,但单元格始终可以 selected,所以不,我只需要防止它发生。
我注意到当单元格被 selected 时添加了两个 css 类 :ui-state-highlight ui-cell-editing
.
我所做的解决方案是防止其子项中没有 .ui-cell-editor
的列的默认行为如下:
$(".ui-editable-column").click(function(event){
if(!$(this).find('.ui-cell-editor').length){
event.preventDefault();
return false;
}
});