paginating multi-level data in pptx helper



  • Hello, I'm trying to paginate an inner data object represented by the suites table on the playground example. The max lines on that table can be max of 3. Is there a way to repeat a building record with remaining suites if there are more than 3 suites associated to a give building (as in building 432)? The overall max number of suites in a building can be upwards of 20 in production.

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

    I have seen a previous post discussing pagination here: https://forum.jsreport.net/post/12353, but I can't seem to be able to port this into a multilevel object structure like in the example.


  • administrators

    hi @lukuser

    i believe this should work, take a look

    https://playground.jsreport.net/w/bjrmatos/DxCB_tRG

    i have modified the pptx to have this call at the top {{pptxSlides (chunksBySuites buildings)}} and then just added the chunksBySuites helper

    function* _chunk(buildings, maxSuites) {
      for (let i = 0; i < buildings.length; i ++) {
        const { suites, ...rest } = buildings[i]
    
        for (let j = 0; j < suites.length; j += maxSuites) {
            const newBuilding = { ...rest }
            newBuilding.suites = suites.slice(j, j + maxSuites)
            yield newBuilding;
        }
      }
    }
    
    function chunksBySuites(buildings) {
        const maxSuites = 3
        return [..._chunk(buildings, maxSuites)]
    }
    

Log in to reply
 

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