File: needtable.rst

package info (click to toggle)
sphinx-needs 5.1.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 11,924 kB
  • sloc: python: 21,132; javascript: 187; makefile: 89; sh: 29; xml: 10
file content (357 lines) | stat: -rw-r--r-- 7,753 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
.. _needtable:

needtable
=========

.. versionadded:: 0.2.0

**needtable** generates a table, based on the result of given filters.

.. need-example::

   .. needtable:: Example table
      :tags: main_example
      :style: table

We use the argument of a ``needtable`` as caption for the table.

Options
-------

.. note::

    **needtable** supports the full filtering possibilities of **Sphinx-Needs**.
    Please see :ref:`filter` for more information.


.. _needtable_columns:

columns
~~~~~~~
A comma/semicolon separated string used to define the position of specific columns.
For instance::

    .. needtable::
       :columns: id;title;tags


This will show the columns *id*, *title* and *tags* in the order given.

.. need-example::

   .. needtable::
      :columns: id;title;tags

You can set all options of a need (incl. :ref:`needs_extra_options`) as a column.
This also includes internal options like ``docname`` (Use `:layout: debug` on a need for a complete list)

If you set **:columns:**, the current table will not use the value of config parameter :ref:`needs_table_columns`.

Tables with a lot of columns will get a horizontal scrollbar in HTML output.

**DataTable style**

.. need-example::

   .. needtable::
      :tags: test
      :columns: id;title;tags;status;docname;lineno,is_external,is_need;is_part;content

**Normal style**

.. need-example::

   .. needtable::
      :tags: test
      :style: table
      :columns: id;title;tags;status;docname;lineno,is_external,is_need;is_part;content

.. _needtable_colwidths:

colwidths
~~~~~~~~~

.. versionadded:: 0.7.4

A comma separated list of lengths or percentages used to define the width of each column.

It has the same meaning as the ``width options`` of
`listtable <https://docutils.sourceforge.io/docs/ref/rst/directives.html#list-table>`_ directive.

.. need-example::

  .. needtable::
     :tags: test
     :columns: id,title,status
     :colwidths: 50,40,10
     :style: table

.. _needtable_custom_titles:

Custom column titles
....................
You can customize each column title by following this syntax for its definition: ``OPTION as "My custom title"``.
The characters ``,`` or ``;`` are not allowed.

.. need-example::

   .. needtable::
      :tags: test
      :columns: id;title as "Headline"; tags as "Labels"
      :style: table

.. _needtable_show_filters:

show_filters
~~~~~~~~~~~~

If set, we add the used filter above the table:

.. need-example::

   .. needtable::
      :tags: test
      :columns: id;title;tags
      :show_filters:
      :style: table

.. _needtable_style:

style
~~~~~
Allows you to set a specific style for the current table.

Supported values are:

 * table
 * datatables

Overrides config parameter :ref:`needs_table_style` if set.

.. dropdown:: Show example

   .. need-example::

      .. needtable::
         :style: table

      .. needtable::
         :style: datatables

.. _needtable_show_parts:

show_parts
~~~~~~~~~~

.. versionadded:: 0.3.6

Adds an extra table row for each :ref:`need_part` found inside a filtered need.

It adds the part rows directly under the related need’s row, and their id and title get a prefix.

To change the prefix please read :ref:`needs_part_prefix`.

.. need-example::

   .. needtable::
      :tags: test_table
      :filter: is_need
      :show_parts:
      :columns: id;title;outgoing;incoming
      :style: table

.. dropdown:: Show above example's configuration

   .. need-example::

      .. req:: Test need with need parts
         :id: table_001

         :np:`(1) Part 1 of requirement`.

         :np:`(2) Part 2 of requirement`.

         :np:`(3) Part 3 of requirement`.

      .. spec:: Specifies part 1
         :id: table_002
         :links: table_001.1

      .. spec:: Specifies part 2
         :id: table_003
         :links: table_001.2

.. _needtable_style_row:

style_row
~~~~~~~~~

.. versionadded:: 0.4.1

You can use the ``style_row`` option to set a specific class-attribute for the table-row representation and use **CSS** to select the class-attribute

Also, you can set specific layout for the row.

.. need-example::

  .. needtable::
     :tags: ex_row_color
     :style_row: needs_blue_border


Row style based on specific need value
......................................

You can use :ref:`dynamic_functions` to derive the value for ``style_row`` based on a specific value of the
documented need in the row.

.. need-example::

   .. needtable::
      :tags: ex_row_color
      :columns: id, title, status
      :style_row: needs_[[copy("status")]]

In this example we set ``style_row`` to ``needs_[[copy("status")]]``, so the status of each need will be
part of the row style.

.. note::

   If ``style_row`` contains whitespaces, they get automatically replaced by ``_`` to get a valid css class name.

   So a copied status value like ``in progress`` will become ``in_progress``.

.. dropdown:: Show used configuration

   **needtable**

   .. code-block:: rst

      .. needtable::
         :tags: ex_row_color
         :columns: id, title, status
         :style_row: needs_[[copy("status")]]

   **needs as input**

   .. req:: Implemented spec
      :id: EX_ROW_1
      :tags: ex_row_color
      :status: implemented

   .. req:: Not implemented spec
      :id: EX_ROW_2
      :tags: ex_row_color
      :status: open

   .. req:: Spec under progress
      :id: EX_ROW_3
      :tags: ex_row_color
      :status: in progress

   **inside a provided css file**

   .. code-block:: css

      tr.needs_implemented {
       background-color: palegreen !important;
      }

      tr.needs_open {
          background-color: palevioletred !important;
      }

      tr.needs_in_progress {
          background-color: palegoldenrod !important;
      }

      /* This sets values for the status column */
      tr.needs_in_progress td.needs_status p {
          background-color: #1b6082;
          padding: 3px 5px;
          text-align: center;
          border-radius: 10px;
          border: 1px solid #212174;
          color: #ffffff;
      }


.. _needtable_sort:

sort
~~~~
.. versionadded:: 0.4.3

Option to sort the filtered-results based on a key.

The sort-value must be compatible with the options supported by the :ref:`filter_string`, and the addressed need-value
must have the type ``string``, ``float`` or ``int``.

By default, we use ``id_complete`` if we don't set a sort option.

.. need-example::

   .. needtable::
      :tags: ex_row_color
      :style: table

In this case, we set the sort option to ``status``. So *EX_ROW_3* is above of *EX_ROW_2*.

.. need-example::

   .. needtable::
      :tags: ex_row_color
      :style: table
      :sort: status

.. dropdown:: Show used configuration

   .. code-block:: rst

      .. needtable::
         :tags: ex_row_color
         :style: table

      .. needtable::
         :tags: ex_row_color
         :style: table
         :sort: status

.. note::

   Sorting only works if you use the standard sphinx-table for output: ``:style: table``.
   By default, tables generated with DatabTables uses Javascript to sort results.


.. _needtable_class:

class
~~~~~
.. versionadded:: 0.7.4

You can set additional class-names for a ``needtable`` using the ``class`` option. Mostly used for HTML output.
It supports comma separated values and will add classes to the already set classes by Sphinx-Needs.

.. code-block:: css
   :caption: custom.css

    table.class_red_border {
        border: 3px solid red;
    }


.. need-example::

   .. needtable::
      :tags: test
      :columns: id,title,status
      :style: table
      :class: class_red_border

common filters
~~~~~~~~~~~~~~

* :ref:`option_status`
* :ref:`option_tags`
* :ref:`option_types`
* :ref:`option_filter`