igniteui-angular icon indicating copy to clipboard operation
igniteui-angular copied to clipboard

Feature request - Conditional row selection capability

Open tkiryu opened this issue 8 years ago • 3 comments

Scenario what I'd like to achieve

I'd like to change whether a row is selectable or not row by row according to its cell value or something.

For example

Angular material datatable has this kind of capability. Here is a sample. https://stackblitz.com/edit/angular-material-datatable

I implemented this sample that only even rows are selectable. Angular material datatable is fully customizable despite the checkbox column.

Expected result

igx-grid has header template and row template for row selection, but they are not exposed as API.

// header template
        <ng-container *ngIf="rowSelectable">
            <div class="igx-grid__cbx-selection" #headerCheckboxContainer>
                <igx-checkbox [checked]="allRowsSelected" (change)="onHeaderCheckboxClick($event)" disableRipple="true" [aria-label]="headerCheckboxAriaLabel" #headerCheckbox></igx-checkbox>
            </div>
        </ng-container>

// row template
<ng-container *ngIf="rowSelectable">
    <div class="igx-grid__cbx-selection">
        <igx-checkbox [checked]="isSelected" (change)="onCheckboxClick($event)" disableRipple="true" [aria-label]="rowCheckboxAriaLabel"></igx-checkbox>
    </div>
</ng-container>

If they are exposed and can refer to a row data,

  • header and row template for checkbox column for row selection.
  • row template can refer to each row data. I would be able to achieve my scenario like I am able to do that with Angular material datatable.

This is just my idea. If you have any better ideas, that'll be great!

I'd appreciate your consideration.

tkiryu avatar May 02 '18 04:05 tkiryu

For the moment row selection doesn't support such a functionality. But the grid has custom templates for header (use igxHeader directive) and cell (use igxCell directive). So if you have, for example in the data source a boolean that specifies if the row needs a row selector, then you can define custom cell template with checkbox inside. In addition you can define igHeader template with checkbox and have header checkbox also. Basically this means that you need to define your own selection feature and disable the grid one. Note also that in the case with the igxGrid, its always good to bind the custom cell checkbox with data source value, instead of using odd/eval, because grid is virtual and it cannot depend on visual indexes.

Why we don't have such a functionality out of the box for the igxGrid row selection:

  1. Material guidelines for data tables has checkboxes for all columns.
  2. This is additional logic that will complicate the control will impact performance.
  3. The Material sample you have shown, basically is a custom row selection, the thing above that I'm suggesting you to try with igxGrid. So if this can be achieved in application using igxCell and igxHeader directives, then we don't need to add it igxGrid. Especially if this is not a common scenario.

If there are a lot of requests on scenarios like this, what @rkaraivanov suggests as a future feature, could be to have template-able igxGrid row selector. This is a matter of discussion and it basically depends on the number of real scenarios that need to hide row selection for some of the rows.

Lipata avatar Jul 24 '18 14:07 Lipata

@tkiryu any updates on this issue? Thank you!

Lipata avatar Aug 21 '18 13:08 Lipata

@tkiryu i'm closing this once since you have not answered for a while. Reopen if needed

SlavUI avatar Sep 20 '18 06:09 SlavUI