Skip to content

Commit 04cc519

Browse files
committed
minor #10394 Documented the setColumnMaxWidth() method (javiereguiluz)
This PR was merged into the master branch. Discussion ---------- Documented the setColumnMaxWidth() method This fixes #10030. Commits ------- 00db5a3 Documented the setColumnMaxWidth() method
2 parents 75a1fd8 + 00db5a3 commit 04cc519

File tree

1 file changed

+33
-7
lines changed

1 file changed

+33
-7
lines changed

components/console/helpers/table.rst

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,19 @@ method to set the column widths explicitly::
7676

7777
In this example, the first column width will be ``10``, the last column width
7878
will be ``30`` and the second column width will be calculated automatically
79-
because of the ``0`` value. The output of this command will be:
79+
because of the ``0`` value.
80+
81+
You can also set the width individually for each column with the
82+
:method:`Symfony\\Component\\Console\\Helper\\Table::setColumnWidth` method.
83+
Its first argument is the column index (starting from ``0``) and the second
84+
argument is the column width::
85+
86+
// ...
87+
$table->setColumnWidth(0, 10);
88+
$table->setColumnWidth(2, 30);
89+
$table->render();
90+
91+
The output of this command will be:
8092

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

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

103113
// ...
104-
$table->setColumnWidth(0, 10);
105-
$table->setColumnWidth(2, 30);
114+
$table->setColumnMaxWidth(0, 5);
115+
$table->setColumnMaxWidth(1, 10);
106116
$table->render();
107117

118+
The output of this command will be:
119+
120+
.. code-block:: terminal
121+
122+
+-------+------------+--------------------------------+
123+
| ISBN | Title | Author |
124+
+-------+------------+--------------------------------+
125+
| 99921 | Divine Com | Dante Alighieri |
126+
| -58-1 | edy | |
127+
| 0-7 | | |
128+
| (the rest of rows...) |
129+
+-------+------------+--------------------------------+
130+
131+
.. versionadded:: 4.2
132+
The ``setColumnMaxWidth()`` method was introduced in Symfony 4.2.
133+
108134
The table style can be changed to any built-in styles via
109135
:method:`Symfony\\Component\\Console\\Helper\\Table::setStyle`::
110136

0 commit comments

Comments
 (0)