ce icon indicating copy to clipboard operation
ce copied to clipboard

How to only display particular attributes of Json data?

Open lyassa opened this issue 6 years ago • 3 comments

I get data from a URL that return json with about 20 attributes. I only need to display 3 of them. I am using the following: columns: [ {title: "attrib1", name: "attrib1"}, {title: "attrib2", name: "attrib2"}, .. ] but then the other 17 attributes are displayed under columns D, E, F, ...

lyassa avatar Dec 02 '19 22:12 lyassa

Found your answer about how to hide a column here https://github.com/paulhodel/jexcel/issues/192, but hopefully I will be able to avoid doing that to 17 columns.

lyassa avatar Dec 02 '19 22:12 lyassa

Hi,

if it possible for you, change your JSON before send in JExcel ? with function .map ?

Example :

let data = [
  {"1996": "7959017", "1997": "7968041", "1998": "7976789","1999": "7992324"},
  {"1996": "10156637", "1997": "10181245", "1998": "10203008", "1999": "10226419" },
  {"1996": "7071850", "1997": "7088906", "1998": "7110001", "1999": "7143991" }
];

let result = data.map(o => ({"1996": o["1996"], "1997": o["1997"]}));

console.log(result);

GBonnaire avatar Dec 03 '19 10:12 GBonnaire

If you have entries in your json, jExcel will show those. If you want to hide, you can use type: hidden.

jexcel(document.getElementById('spreadsheet'), {
    data:data,
    columns: [
        {
            type: 'text',
            title:'Car',
            width:90
        },
        {
            type: 'dropdown',
            title:'Make',
            width:120,
            source:[
                "Alfa Romeo",
                "Audi",
                "Bmw",
                "Chevrolet",
                "Chrystler",
                "Dodge",
                "Ferrari",
              ]
        },
        {
            type: 'hidden',
        },
        {
            type: 'hidden',
        },
        {
            type: 'hidden',
        },
        {
            type: 'hidden',
        },
        {
            type: 'hidden',
        },
        {
            type: 'hidden',
        },
        {
            type: 'hidden',
        },
        {
            type: 'hidden',
        },
        {
            type: 'hidden',
        },
     ]
});

pphod avatar Dec 03 '19 13:12 pphod