简体   繁体   English

禁用行选择,只允许在 PrimeNG 的 Mutliselect 中选择复选框

[英]Disable row selection and just allow checkbox to be selected in Mutliselect of PrimeNG

I am working on a requirement in which i am using PrimeNG multiselect.我正在处理我使用 PrimeNG 多选的要求。 This multiselect has a checkboxes which are followed by texts in it.这个多选有一个复选框,后面跟着文本。 I want to disable the row selection and only allow checkboxes to be selected of these rows.我想禁用行选择,只允许选择这些行的复选框。 Below is the example: Scenerio explained with screenshot:下面是例子: Scenerio 用截图解释:

If i click on text " 1 text ", " 2 text ", etc the values are selected but i want to disable this selection and only allow checkbox to be selected.如果我单击文本“ 1 text ”、“ 2 text ”等,则选择了值,但我想禁用此选择并且只允许选中复选框。

Here is the stackblitz example for reference: Stackblitz Demo click here .以下是 stackblitz 示例供参考: Stackblitz Demo click here

在此处输入图像描述

Following Code which i used in my component html: <p-multiSelect [options]="items" defaultLabel="Select items" [showHeader]="false" </p-multiSelect>以下我在组件 html 中使用的代码: <p-multiSelect [options]="items" defaultLabel="Select items" [showHeader]="false" </p-multiSelect>
Code for items in array used in dropdown:下拉列表中使用的数组项的代码:

items: SelectItem[] = [
  { value: 1, label: '1 text' },
  { value: 2, label: '2 text ' },
  { value: 3, label: '3 text' },
 ];
}

Check this Stackblitz link检查此Stackblitz 链接


SOLUTION 1: As this selection is default behavior of primeNg multiSelect so with onChange event Emitter of p-multiSelect I am removing the added value or adding the removed value on deselect value.解决方案 1:由于此选择是 primeNg multiSelect 的默认行为,因此对于 p-multiSelect 的onChange事件发射器,我正在删除添加的值或在取消选择值上添加删除的值。

SOLUTION 2: Using event.stopPropagation() but this works only if I click label but clicking row still select/deselect value.解决方案 2:使用event.stopPropagation()但这仅在我单击 label 但单击行仍选择/取消选择值时才有效。

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

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