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

[Console] Add columns width setter documentation #6296

Merged
merged 2 commits into from
Mar 6, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions components/console/helpers/table.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,27 @@ You can add a table separator anywhere in the output by passing an instance of
| 80-902734-1-6 | And Then There Were None | Agatha Christie |
+---------------+--------------------------+------------------+

The width of the columns are automatically set using the width of their contents by default. You can change this behavior via :method:`Symfony\\Component\\Console\\Helper\\Table::setColumnWidths`::

// Sets the left column to 10 characters, the middle to 0, and the right to 30 characters.
// The left two columns will effectively be 13 and 24 characters, as the columns' content don't fit within the set values.
$table->setColumnWidths(array(10, 0, 30));
$table->render();

This code results in:

.. code-block:: text

+---------------+--------------------------+--------------------------------+
| ISBN | Title | Author |
+---------------+--------------------------+--------------------------------+
| 99921-58-10-7 | Divine Comedy | Dante Alighieri |
| 9971-5-0210-0 | A Tale of Two Cities | Charles Dickens |
+---------------+--------------------------+--------------------------------+
| 960-425-059-0 | The Lord of the Rings | J. R. R. Tolkien |
| 80-902734-1-6 | And Then There Were None | Agatha Christie |
+---------------+--------------------------+--------------------------------+

The table style can be changed to any built-in styles via
:method:`Symfony\\Component\\Console\\Helper\\Table::setStyle`::

Expand Down