issues representing docx table within "each" loop



  • Hello,

    I'm trying to create a docx report with submarkets array, and a nested items array. I want each submarket to repeat a table of items. Here's a playground ilustrating my problem:

    https://playground.jsreport.net/w/lukuser/cleGQAvm

    Template V2 seems to represent tables for each 2 items one on top of another. While template V2.1 doesn't show any data. The difference between them is the location of the initial tag {{#each submarkets}}. In both templates the submarkets table seems to be correctly between {{#each submarkets}} tag and the closing {{/each}} tag, but in template V2 it is higher (under the black header).



  • Hello, @admin, I'm just following up on this issue.


  • administrators

    hi!

    for template v2.1 is clear that the issue is that the loop does not output anything, for template v2 what is the issue?

    it is the that the rows are overlapping each other, right?

    0_1732297789858_Screenshot 2024-11-22 at 12 .46.45@2x.jpg

    i have added to the backlog to check this case, we will get to it.



  • @bjrmatos , yes, in template v2, the submarket groups overlap each other, and in template v2.1, where the #each tag is only slightly lower, I get no data at all. Thank you for looking into this


  • administrators

    i have checked both templates, i will try to explain why each template does not work as expected.

    in both of your templates the table is defined with text wrapping enabled

    0_1733506327737_Screenshot 2024-12-06 at 12 .31.38@2x.jpg

    when this option is enabled it causes the XML of the paragraphs around the table (both the the one at the top and at the bottom) to be affected. what does this mean?

    it means that visually the representation of the nodes in the template is like this:

    • previous paragraph (visually the one at the top of the table)
    • table
    • next paragraph (visually the one at the bottom of the table)

    however, internally the real representation in the XML is like this:

    • previous paragraph (visually the one at the top of the table)
    • table
    • next paragraph (visually the one at the bottom of the table)

    this behavior produces different results on each of your templates

    for template v2

    0_1733507693540_Screenshot 2024-12-06 at 12 .53.24@2x.jpg

    the template produces tables overlapping because this is the normal behavior of a table with text wrapping enabled when there is no text around. if you put two tables with text wrapping enabled and there are no paragraphs around them, the tables will overlap.

    in this case the loop in the XML is represented like this

    • paragraph 1 (start of loop {{#each}})
    • table
    • paragraph 2 (empty one)
    • paragraph 3 (end of loop {{/each}})

    in our docx processing if we detect paragraphs with no more text other than the handlebars calls, then after processing the template, these paragraphs are removed in order for them to not affect layout, so based on this the final result of the loop is this:

    ------ iteration 1 -----------

    • table
    • paragraph 2 (empty one)
      ------ iteration 2 -----------
    • table
    • paragraph 2 (empty one)
      ------ iteration 3 -----------
    • table
    • paragraph 2 (empty one)
      ------ ...continues... -----------

    this is why the final result is overlapping tables, because for sibling tables (that have text wrapping enabled) to render correctly in MS Word the internal representation should be like this

    • table
    • empty paragraph
    • empty paragraph
    • table
    • empty paragraph
    • empty paragraph

    how to fix the template v2?

    you have two options:

    • you can either disable the text wrapping in the table
    • or prevent the paragraph that contains the end of loop to be removed, if you go with this option then you only need to put a leading space in the paragraph that contains the end of loop. so it should look like this <empty space here>{{/each}}

    with either of these solutions you should be able to produce the expected result

    0_1733509524751_Screenshot 2024-12-06 at 1 .25.04@2x.jpg

    for template v2.1

    0_1733509821081_Screenshot 2024-12-06 at 1 .27.18@2x.jpg

    in this case the loop in the XML is represented like this

    • table
    • paragraph 1 (start of loop {{#each}})
    • paragraph 2 (empty one)
    • paragraph 3 (empty one)
    • paragraph 4 (end of loop {{/each}})

    as you can see, the problem is clear, the loop does not wrap the table, there is only empty paragraphs in the loop body, so this template does not produce anything meaningful

    how to fix the template v2.1?

    you have two options:

    • you can either disable the text wrapping in the table
    • or you can put the start of loop in a paragraph that is not around the table, you can create a new paragraph before the paragraph 1 and there put that start of the loop, just similar to the template v2

    i hope this clarifies the reason of the results, we don't plan to do something to change the output when tables with text wrapping is enabled, as described there is easy solution for this just by changing the template. applying a solution that might try to "fix" this automatically will cause side effects on other cases.


Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.