How To Restart Numbering Of Ordered List In DOCX JS
JavaScript
16/01/2023
To restart the numbering of an ordered list, we need to give each list a unique instance id throughout the entire document. This instance ID is set in the Paragraph
object.
JAVASCRIPT
new Paragraph({ text: "A single list item", numbering: { reference: "numbering-style-1", level: 0, instance: 1, // Unique for each list },})
Gotcha
If you plan on implementing any nested lists, you will need to ensure a unique ID for them as well. Here's an example to visualize the potential problem.
TEXT
List A with a unique ID of '1'1. (id 1)-- a. (nested list A needs a new ID of '2')-- b. (id 2)2. (id 1)-- a. (Nested list 2A needs another unique ID of '3' to avoid becoming 'c')
List B with a new ID of '4'1.2.3.