From 00db5a3c36410e2fc8b55bf052c0ed5fff7191bd Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Mon, 24 Sep 2018 17:11:44 +0200 Subject: [PATCH] Documented the setColumnMaxWidth() method --- components/console/helpers/table.rst | 40 +++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/components/console/helpers/table.rst b/components/console/helpers/table.rst index 792f6f2accd..1865caaf881 100644 --- a/components/console/helpers/table.rst +++ b/components/console/helpers/table.rst @@ -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 @@ -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`::