Skip to content

Documented the setColumnMaxWidth() method #10394

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

Merged
merged 1 commit into from
Sep 25, 2018
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
40 changes: 33 additions & 7 deletions components/console/helpers/table.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,19 @@ method to set the column widths explicitly::

In this example, the first column width will be ``10``, the last column width
will be ``30`` and the second column width will be calculated automatically
because of the ``0`` value. The output of this command will be:
because of the ``0`` value.

You can also set the width individually for each column with the
:method:`Symfony\\Component\\Console\\Helper\\Table::setColumnWidth` method.
Its first argument is the column index (starting from ``0``) and the second
argument is the column width::

// ...
$table->setColumnWidth(0, 10);
$table->setColumnWidth(2, 30);
$table->render();

The output of this command will be:

.. code-block:: terminal

Expand All @@ -95,16 +107,30 @@ widths. If the contents don't fit, the given column width is increased up to the
longest content length. That's why in the previous example the first column has
a ``13`` character length although the user defined ``10`` as its width.

You can also set the width individually for each column with the
:method:`Symfony\\Component\\Console\\Helper\\Table::setColumnWidth` method.
Its first argument is the column index (starting from ``0``) and the second
argument is the column width::
If you prefer to wrap long contents in multiple rows, use the
:method:`Symfony\\Component\\Console\\Helper\\Table::setColumnMaxWidth` method::

// ...
$table->setColumnWidth(0, 10);
$table->setColumnWidth(2, 30);
$table->setColumnMaxWidth(0, 5);
$table->setColumnMaxWidth(1, 10);
$table->render();

The output of this command will be:

.. code-block:: terminal

+-------+------------+--------------------------------+
| ISBN | Title | Author |
+-------+------------+--------------------------------+
| 99921 | Divine Com | Dante Alighieri |
| -58-1 | edy | |
| 0-7 | | |
| (the rest of rows...) |
+-------+------------+--------------------------------+

.. versionadded:: 4.2
The ``setColumnMaxWidth()`` method was introduced in Symfony 4.2.

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

Expand Down