Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion for igx-grid group by row template #12752

Closed
punker76 opened this issue Mar 9, 2023 · 1 comment · Fixed by #12768
Closed

Suggestion for igx-grid group by row template #12752

punker76 opened this issue Mar 9, 2023 · 1 comment · Fixed by #12768
Assignees
Labels
grid: groupby 🧰 feature-request ✅ status: resolved Applies to issues that have pending PRs resolving them, or PRs that have already merged.

Comments

@punker76
Copy link

punker76 commented Mar 9, 2023

In igx-grid it's possible to define a formatter for a column. This is then used for the cell display and the filter ui.

But it's not used for the default group by row template.

Here is a simple sample:

  • let's say we have a column which is internally a number (enumeration value), starting from 0 = Available to n
  • if I use a formatter then it will be shown as expected in cell

image

  • if I now group by this column the template will show not the formatted value, it shows the number value behind
  • it's possible to copy the default template and change it to use the formatter
    <ng-template igxGroupByRow let-groupRow>
      <div class="igx-group-label">
        <igx-icon class="igx-group-label__icon">group_work</igx-icon>
        <span class="igx-group-label__column-name">
          {{ groupRow.column && groupRow.column.header ? groupRow.column.header : groupRow.expression ? groupRow.expression.fieldName : "" }}:
        </span>

        <ng-container *ngIf="groupRow.column.formatter; else default">
          <span class="igx-group-label__text">{{ groupRow.column.formatter(groupRow.value) }}</span>
        </ng-container>
        <ng-template #default>
          <ng-container *ngIf="groupRow.column.dataType === 'boolean' || groupRow.column.dataType === 'string'; else defaultPiped">
            <span class="igx-group-label__text">{{ groupRow.value }}</span>
          </ng-container>
        </ng-template>
        <ng-template #defaultPiped>
          <ng-container *ngIf="groupRow.column.dataType === 'number'">
            <span class="igx-group-label__text">{{ groupRow.value | number }}</span>
          </ng-container>
          <ng-container *ngIf="groupRow.column.dataType === 'date' || groupRow.column.dataType === 'dateTime' || groupRow.column.dataType === 'time'">
            <span class="igx-group-label__text">{{
              groupRow.value | date : groupRow.column.pipeArgs.format : groupRow.column.pipeArgs.timezone : locationsGrid.locale
            }}</span>
          </ng-container>
        </ng-template>

        <igx-badge
          [value]="groupRow.records ? groupRow.records.length : 0"
          class="igx-group-label__count-badge"
          style="color: white; padding-left: 4px; padding-right: 4px"
        >
        </igx-badge>
      </div>
    </ng-template>
  • my suggestion is now, to add this to the default group by row template

related code:

<ng-container *ngIf="dataType === 'boolean' || dataType === 'string'; else default">
<span class="igx-group-label__text">{{ groupRow.value }}</span>
</ng-container>
<ng-template #default>
<ng-container *ngIf="dataType === 'number'">
<span class="igx-group-label__text">{{ groupRow.value | number }}</span>
</ng-container>
<ng-container *ngIf="dataType === 'date' || dataType === 'dateTime' || dataType === 'time'">
<span class="igx-group-label__text">{{ groupRow.value |
date:groupRow.column.pipeArgs.format:groupRow.column.pipeArgs.timezone:grid.locale }}</span>
</ng-container>
</ng-template>

changed code:

        <ng-container *ngIf="groupRow.column.formatter; else default">
          <span class="igx-group-label__text">{{ groupRow.column.formatter(groupRow.value) }}</span>
        </ng-container>
        <ng-template #default>
          <ng-container *ngIf="dataType === 'boolean' || dataType === 'string'; else defaultPiped">
            <span class="igx-group-label__text">{{ groupRow.value }}</span>
          </ng-container>
        </ng-template>
        <ng-template #defaultPiped>
          <ng-container *ngIf="dataType === 'number'">
            <span class="igx-group-label__text">{{ groupRow.value | number }}</span>
          </ng-container>
          <ng-container *ngIf="dataType === 'date' || dataType === 'dateTime' || dataType === 'time'">
            <span class="igx-group-label__text">{{
              groupRow.value | date : groupRow.column.pipeArgs.format : groupRow.column.pipeArgs.timezone : locationsGrid.locale
            }}</span>
          </ng-container>
        </ng-template>

result

2023-03-09_21h34_12

@ChronosSF ChronosSF assigned dkamburov and ChronosSF and unassigned dkamburov Mar 10, 2023
@ChronosSF ChronosSF added 🛠️ status: in-development Issues and PRs with active development on them and removed 👀 status: in-review Issue is currently being reviewed labels Mar 13, 2023
@ChronosSF
Copy link
Member

One thing to consider here is that the cell formatter receives the whole record because often the result depends on values from other columns. With groupby the formatter will execute with say the first record of the group.

@ChronosSF ChronosSF added ✅ status: resolved Applies to issues that have pending PRs resolving them, or PRs that have already merged. and removed 🛠️ status: in-development Issues and PRs with active development on them labels Mar 15, 2023
ChronosSF added a commit that referenced this issue Mar 21, 2023
…12768)

* feat(groupby): adding cell-like formatting for group values #12752

* chore(groupby): adding changelog, fixing lint

* fix(groupby): removing leftovers from the tempalte

* chore(groupby): fixing an issue with non-existing columns

---------

Co-authored-by: Deyan Kamburov <dkamburov@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
grid: groupby 🧰 feature-request ✅ status: resolved Applies to issues that have pending PRs resolving them, or PRs that have already merged.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants