Home > Back-end >  Primeng data table limit the max 4 row selectable
Primeng data table limit the max 4 row selectable

Time:05-19

I'm using angular 11 with primeng library. Objective is to select max 4 records and show comparison on dialogue box. Using <p-tableCheckboc for row selection. But chalenge is there is no arrangment for limiting the max no of row selection. Either you select one record or multiple.

CodePudding user response:

Have a look over the selection property. It might help you implement this custom behavior.

The primeng docs say that this property reflects the

Selected row in single mode or an array of values in multiple mode.

So, in your case, since you allow multiple selections, selection will be an array of values. In this case, you could do something like this on your table rows:

[disabled] = "selection.length === numberOfMaxSelections"
  • Related