xlsx-template icon indicating copy to clipboard operation
xlsx-template copied to clipboard

Implement in tables {people: {users: [{name: "John Smith"}]}}

Open romkadj opened this issue 6 years ago • 5 comments

    var values = {
        people: [
            {
                name: 'John Smith',
                age: 20,
                test: { name: 'Smith' },
            },
            {
                name: 'Bob Johnson',
                age: 22,
                test: { name: 'Johnson' },
            },
        ],
        people: {
            users: [
                {
                    name: 'John Smith User',
                    age: 20,
                    test: { name: 'Smith' },
                },
                {
                    name: 'Bob Johnson User',
                    age: 22,
                    test: { name: 'Johnson' },
                },
            ],
            admins: [
                {
                    name: 'John Smith Admin',
                    age: 20,
                    test: { name: 'Smith' },
                },
                {
                    name: 'Bob Johnson Admin',
                    age: 22,
                    test: { name: 'Johnson' },
                },
            ],
        },
    };

So for example I have this object values that I want to put into template.

${table:people.name} - this placeholder works ${table:peopleGroup.users.name} - this does not work, in result value is blank

romkadj avatar Aug 10 '18 08:08 romkadj

There is no "peopleGroup" field in your values

pwarelis avatar Feb 26 '19 20:02 pwarelis

@romkadj example contains missprint, this is right. However, arrays in nested objects not rendered.

{
  rows: [
    {name: 'foo'}
  ],
  rowsNested: {
    rows: [
      {name: 'foo'}
    ],
  }
}

${table:rows.name} - work ${table:rowsNested.rows.name} - not work

dbykadorov avatar Apr 12 '19 13:04 dbykadorov

You can nest objects, not arrays. Nesting an array inside another makes your data structure three dimensional. How do you represent that on a spreadsheet?

Why don't you flatten all your arrays before you pass it to the generator?

pwarelis avatar Apr 12 '19 17:04 pwarelis

@pwarelis I'm not familiar with this lib yet but yes - I just did the same thing - moved array on top level of object passed into template =)

dbykadorov avatar Apr 12 '19 18:04 dbykadorov

I have a list of object which are dynamically grouped which basically means I have a nested Array. We represent those in a spreadsheet into multiple groups of tables. our sample JSON : { "ParentName": "Testunt", "Description": "This is tEst Description Show me", "TesVal": "", "GroupedList": [ { "GroupName": "asdasddfs", "GroupList": [ { "TotalNumber": 23, "Qty": 1, "Code": "XYz" }, { "TotalNumber": 23, "Qty": 12, "Code": "WKP" } ] }, { "GroupName": "PUMPTYPEA", "GroupList": [ { "TotalNumber": 23, "Qty": 1, "Code": "SKP" }, { "TotalNumber": 23, "Qty": 1, "Code": "SXKP" } ] } ] }

xsudiptaster avatar Nov 20 '20 16:11 xsudiptaster