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

Feature request - Conditional cell styling capability #1079

Closed
tkiryu opened this issue Apr 20, 2018 · 1 comment
Closed

Feature request - Conditional cell styling capability #1079

tkiryu opened this issue Apr 20, 2018 · 1 comment
Assignees
Labels
🧰 feature-request version: 6.2.x ✅ status: resolved Applies to issues that have pending PRs resolving them, or PRs that have already merged.

Comments

@tkiryu
Copy link

tkiryu commented Apr 20, 2018

Scenario what I'd like to achieve

I'd like to conditionally change cell background color according to another cell value or something. I think this is a common scenario and am advanced story of this.

https://github.com/IgniteUI/igniteui-angular/wiki/igxGrid-Specification
Story 12: As an end user, I expect styling capabilities allowing me to set the cell background color and the cell content font color to a custom color provided via its hex encoded string.

Problem

In order to achieve that, only we can do for now is use cell template like this.

// Only when booleanColumn's cell value is true, "checked" class is added to the cell template.
<igx-column [field]="'stringColumn'" [dataType]="'string'" [header]="'string1'">
  <div *igxCell="let value; let cell = cell" [class.checked]="cell.row.rowData['booleanColumn']">
    {{ value }}
  </div>
</igx-column>

.checked {
  color: blue;
  font-weight: bold;
  background-color: salmon;
}

But, It doesn't work as I expect because the igx-grid-cell has default padding so that background color of the cell template can not be filled inside the cell.
image

Current Solution

So I have to remove default padding of the igx-grid-cell and put padding to the cell template inside the cell.

<igx-column [field]="'stringColumn'" [dataType]="'string'" [header]="'string2'" [cellClasses]="'noPadding'">
  <div class="padding" *igxCell="let value; let cell = cell" [class.checked]="cell.row.rowData['booleanColumn']">
    {{ value }}
  </div>
</igx-column>

:host::ng-deep {
  // remove padding from the cell
  .noPadding {
    padding: 0;
  }
  // put padding to the cell template inside the cell
  .padding {
    padding: 1rem 1.5rem;
  }
}

It works as we expect.
image

But this solution is a little hassle.

Here is a sample what I explained above. You can change cell background dynamically by clicking checkbox.
https://stackblitz.com/edit/igx-grid-cell-style2

Expect

I'd like a feature that we can attach conditional classes to the cell directly so that we don't have to remove default padding.

For example, cellClassses accepts function in addition to string like below.

<igx-column [field]="'stringColumn'" [dataType]="'string'" [header]="'string2'" [cellClasses]="conditionalStyleFunc">

// This function takes cell value and its row data, then returns classes as string.
conditionalStyleFunc(cellValue, rowData): string {
  const cellClasses = ['foo'];
  if (cellValue === 'something') {
    cellClasses.push('bar');
  }
  if (rowData['anotherCell'] === true) {
    cellClasses.push('baz');
  }
  // if all the condition matches, "foo bar baz" would be returned.
  return cellClasses.join(' ');
}

It's just an idea. But such a capability would enable the developers more easily handle conditional styling not only background color but also many other css props for cells.

I would appreciate your consideration.

@SlavUI SlavUI assigned bkulov and SAndreeva and unassigned simeonoff, SDinev and desig9stein Aug 31, 2018
@bkulov bkulov added the 🛠️ status: in-development Issues and PRs with active development on them label Sep 10, 2018
SAndreeva added a commit that referenced this issue Sep 13, 2018
@SAndreeva SAndreeva 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 Sep 19, 2018
@tkiryu
Copy link
Author

tkiryu commented Sep 20, 2018

All, thank you sooo much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🧰 feature-request version: 6.2.x ✅ status: resolved Applies to issues that have pending PRs resolving them, or PRs that have already merged.
Projects
None yet
Development

No branches or pull requests

7 participants