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

add style in a cell #315

Closed
TheMalloum opened this issue Apr 20, 2017 · 17 comments
Closed

add style in a cell #315

TheMalloum opened this issue Apr 20, 2017 · 17 comments

Comments

@TheMalloum
Copy link

Hi,

I want to add style dynamically in a cell.
for exemple
valuePrepareFunction : (cell, row) => {
return <span class="myclass" style="background-color: yellow !important;">${cell}</span>;
}

no problem for my class but the style is ignore.

Do you know why ?

@lexzhukov
Copy link
Contributor

lexzhukov commented Apr 20, 2017

try to use [style.background-color]="value" instead of style="...."

@TheMalloum
Copy link
Author

Hi,

I use this, but it doesn't works.

valuePrepareFunction : (cell, row) => {
return <span [style.background-color]="'red'">${cell}</span>;
}

thanks for your answer

@nnixaa
Copy link
Contributor

nnixaa commented Apr 22, 2017

Hey @TheMalloum, your first example should work, just specify the column type as 'html'.

@TheMalloum
Copy link
Author

TheMalloum commented Apr 22, 2017

Hi @nnixaa,

that is my columns settings but it doesn't works, color is ignore.

    color: {
      type: "html",
      title: 'color',
      filter: false,
      valuePrepareFunction: (cell, row) => {
          return `<span class="fa fa-users" style="color:${cell};" >${cell}</span>`;
      }

thanks

@TheMalloum
Copy link
Author

Hi @nnixaa,

I want to know if is possible, if is it, i could validate the use of ng2-smart-table.

@lexzhukov
Copy link
Contributor

@TheMalloum for your example, you can use only the classes or use a custom view component.. Please, take a look at this docs.

@TheMalloum
Copy link
Author

Hi @nnixaa,
thanks a lot

@vmanishasannu
Copy link

For People Who still stuck to add a class to a cell in the table
below is a sample code where taskStatus is the column name , title: 'Task Status' is the displayed title in the table
settings = {
columns: {
taskStatus: {
title: 'Task Status',
type: 'html',
filter: false,
valuePrepareFunction: (value) => {
return '

' + value + '
';
}
}
}
};

@Balachandar1996
Copy link

try this one,
valuePrepareFunction: (data) => { return '<p class="cell_right">' + data + '</p>'; },

CSS
:host /deep/ .cell_right {
width:100%;
height: 100%;
text-align: right;
}
thanks ;)

@amethiarunmaurya
Copy link

Hello,
Please help me i want to use row groupping in ngx-smart table .
Plese share some example code

@Balachandar1996
Copy link

Balachandar1996 commented Aug 30, 2018 via email

@lukele1607
Copy link

Hi @TheMalloum,
Did you resolve this problem ?
I get same issues. I have tried component, renderConponent and valuePrepareFunction but all of them not working. ng2-smart-table is ignore style

@lukele1607
Copy link

Hi, It is work fine with renderConponent .
Thank for all

@toilabeos
Copy link

@lukele1607 can you give me example about this?

@lukele1607
Copy link

lukele1607 commented Apr 22, 2019

@khyynld : code sample

generateTable() {
    this.tableSettings = {
      actions: false,
      hideSubHeader: true,
      columns: {
        tunnel: {
          title: tunnelHeader,
          filter: false,
          type: 'string',
        },
        tunnelState: {
          title: tunnelState,
          filter: false,
          type: 'custom',
          renderComponent: ProgressComponent
        },
      },
      pager:
      {
        perPage: 4
      }
    };
  }

progress.component.ts:

import { Component, OnInit, Input } from '@angular/core';
import { ViewCell } from 'ng2-smart-table';

@Component({
  selector: 'app-progress',
  template: `
    <div class="progress" >
      <div class="{{stateClass}}" aria-valuemin="0" aria-valuemax="100" [attr.aria-valuenow]="percentage"
        role="progressbar" [style.width]="styleWidth" >
          {{percentage}}%
      </div>
  </div>`
})
export class ProgressComponent implements ViewCell, OnInit {

  @Input() value: string | number;
  @Input() rowData: any;
  stateClass: string;
  percentage: number;
  styleWidth: string;

  constructor() { }

  ngOnInit() {
    this.stateClass = this.rowData.tunnelState.state === '1' ? 'progress-bar bg-success' : 'progress-bar bg-danger';
    this.percentage = this.rowData.tunnelState.percentage;
    this.styleWidth = this.percentage + '%';
  }
}

@WiharlleyWill
Copy link

Change the type oc collum to HTML

nameColumn: { title: "titleColumn", type: "html", valuePrepareFunction: ((data, row) => { if (row.VALUE === 'EXAMPLE') { return '<p class="cell_style">' + data + '</p>'; } else { return

${row.StatusBoleto}

; } }),

Style:
:host /deep/ .cell_style { width:100%; height: 100%; text-align: right; }

@InovantNodeTeam
Copy link

For People Who still stuck to add a class to a cell in the table below is a sample code where taskStatus is the column name , title: 'Task Status' is the displayed title in the table settings = { columns: { taskStatus: { title: 'Task Status', type: 'html', filter: false, valuePrepareFunction: (value) => { return '

' + value + '
';
}
}
}
};

im not able to add class plz help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants