Skip to content

[Console][Table] Apply options/style to table cells #13370

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

Closed
tomzx opened this issue Jan 11, 2015 · 13 comments · Fixed by #37338
Closed

[Console][Table] Apply options/style to table cells #13370

tomzx opened this issue Jan 11, 2015 · 13 comments · Fixed by #37338
Labels
Console Feature Help wanted Issues and PRs which are looking for volunteers to complete them.

Comments

@tomzx
Copy link

tomzx commented Jan 11, 2015

It would be nice if Table was able to be styled as much as a HTML table can.

Use case: Center some cells

I think the way we can approach this with the current implementation is to add an optional $options parameter to the methods adding/setting rows.

The array would look as such:

[
    cellNumber => [
        propertyA => value,
        propertyB => value,
        colspan => value,
        rowspan => value,
        align => left|center|right,
        format => '<info>%s</info>',
    ]
]

By using keyed cell number (for a single row), we can specify data for only specific cells (does not force the user to specify an empty array for each cell).

Any undefined property implies the default values for the table.

@fabpot fabpot added the Console label Feb 5, 2015
@dupuchba
Copy link
Contributor

Do you any other use case other than center a cell ?

@tomzx
Copy link
Author

tomzx commented Feb 18, 2015

This issue is a generalization of #13368. The main objective is to have as much flexibility and features as an HTML table would provide us with.

At one point I considered that the solution to the table problem would be to have php generate an html table which would then be given to the Table helper, which in turn, would convert it to something that can be rendered in a console.

Thus the main points of interest are:

  • Background/foreground coloring
  • Alignment
  • Cell merging
  • Border styling

@aitboudad
Copy link
Contributor

@tomzx in #13438, I used TableCell where we can can specify data for cell,
so I think this is an easy task and I see 2 ways to fix this:

1- Introduce a new TableCellStyle:

$table->addRow([new TableCell("data", ['style' => new TableStyleCell()]), 'data']);

2- add more option in table TableStyleCell:

$cellOption = [
    'rowspan' => 1,
    'colspan' => 2,
   'format' => '%s',
   'align'    => 'left',
];
$table->addRow([new TableCell("data", $cellOption), 'data']);

@fabpot what would be your preferred way ?

@aik099
Copy link

aik099 commented Aug 22, 2015

I also recently had a need to have odd/even table row colors or a way to individually color a row/cell. So 👍 for this.

@freezy-sk
Copy link
Contributor

👍

@regniblod
Copy link

I also recently had a need to add background color to some cells depending on the context. So 👍 for this.

Is there any update?

@fabpot
Copy link
Member

fabpot commented Jul 11, 2017

I think someone needs to implement it and submit a pull request. Sounds like an interesting feature to me.

@andrewtch
Copy link
Contributor

@fabpot , is it still needed?

@fabpot
Copy link
Member

fabpot commented May 30, 2018

I think so :)

@andrewtch
Copy link
Contributor

So what would you prefer? TableCellStyle / options array as stated above or some:

$table->setFormatterCallback(function ($col, $row, $value, $options) {
    $options['format'] = $col == 0 ? '<error>%s</error>' : '<info>%s</info>';

    return $options;
});

@andrewtch
Copy link
Contributor

@fabpot ping )

@wapmorgan
Copy link

+1, Need availability for styling table cells. I'd prefer declarative definition (via array or TableCellStyle).

@Cosmologist
Copy link

+1

@chalasr chalasr added the Help wanted Issues and PRs which are looking for volunteers to complete them. label May 5, 2019
@fabpot fabpot closed this as completed Aug 11, 2020
fabpot added a commit that referenced this issue Aug 16, 2020
This PR was squashed before being merged into the 5.2-dev branch.

Discussion
----------

[Console] added TableCellStyle

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | Fix #13370
| License       | MIT
| Doc PR        | symfony/symfony-docs#... <!-- required for new features -->

Added an opportunity to customize a table cell via TableCellStyle object.

It can be used as

```php
new TableCell(
  'content',
  [
    'style' => new TableCellStyle([
        'align' => 'center',
        'fg' => 'red',
        'bg' => 'green',

        // or
        'cellFormat' => '<info>%s</info>',
    ])
  ]
)
```

See #13370

Commits
-------

aff7628 [Console] added TableCellStyle
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Console Feature Help wanted Issues and PRs which are looking for volunteers to complete them.
Projects
None yet
Development

Successfully merging a pull request may close this issue.