Primeng data table limit the max 4 row selectable


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.


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"

Answered By – CCBet

Answer Checked By – Dawn Plyler (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.