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

Support sorting needtable with order of apperance in the document #1144

Open
chenlijun99 opened this issue Mar 14, 2024 · 4 comments
Open

Support sorting needtable with order of apperance in the document #1144

chenlijun99 opened this issue Mar 14, 2024 · 4 comments

Comments

@chenlijun99
Copy link

Hi! First, thanks for Sphinx-needs. It's very cool!
Maybe I missed something in the documentation, but is it possible to sort the items in the needtable in the order they appear in the source files?
One challenge I see is how to deal with needs coming from multiple files, but maybe something as simple as sort by filename could work?

@chenlijun99
Copy link
Author

I see that each need in needs.json already has the docname and doctype properties. Would it be possible to introduce a property like docsrcline? And then support a list of keys instead of a single key for the sort field of needtable.

@danwos
Copy link
Member

danwos commented Mar 19, 2024

The idea is good, but I'm not sure if sourceline is a good argument.
In a lot of projects, the need objects are stored on different files, get imported by needs.json files and are downloaded from services. Therefore not all of them can be assigned to a source line.

May I ask for your use case, in which sorting by sourceline is a benefit?
This helps us to understand all different ways of using Sphinx-Needs much better :)

However, the idea of supporting multiple parameters for :sort: is good and makes totally sense.

@chenlijun99
Copy link
Author

Thanks for the reply!
My use case is that there is a certain logic order in which I write requirements in a document, where e.g. I start from high-level requirements about the whole system followed by more specific requirements about each part of the system.
Finally, for each document I want to include at the top a need table that provides a concise view of all the requirements in the document, with their incoming and outgoing links. I would like the order of the requirements in the table to match the order in which they appear in the document.

@PhilipPartsch
Copy link
Contributor

If you have local written need elements, you can use lineno.
Here is an example:

.. needtable:: List of software requirements
   :types: sw_req
   :style: table
   :columns: id; title; docname as "document"; lineno as "line no"
   :sort: lineno

The lineno is more correctly set only with sphinx-needs 2.1.0 with support of embedded needs #1150

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants