jexcel load data from ajax with empty cells

433 Views Asked by At
<html>
<script src="https://bossanova.uk/jexcel/v3/jexcel.js"></script>
<link rel="stylesheet" href="https://bossanova.uk/jexcel/v3/jexcel.css" type="text/css" />
<script src="https://bossanova.uk/jsuites/v2/jsuites.js"></script>
<link rel="stylesheet" href="https://bossanova.uk/jsuites/v2/jsuites.css" type="text/css" />

<div id="spreadsheet2"></div>

<script>
jexcel(document.getElementById('spreadsheet2'), {
    jexcel(document.getElementById('spreadsheet2'), {
        url:'/v3/test.json',
        columns: [
            { type:'text', width:300 },
            { type:'text', width:100 },
         ]
    });
});
</script>
</html>

and My External JSON Response is as follow;

{
    "0": {
        "0": "Trawex",            // This should mapped on row=0, col=0
        "1": "Restel",            // This should mapped on row=0, col=1
                                 // now here col 2 and 3 should be filled empty itself.
        "4": "Restel"            // This should mapped on row=0, col=4
    },
    "1": {
        "0": "MP",
        "3": "DZ"
    },
    "4": {
        "8": "$ 333",
        "0": "$ 23.424",
        "13": "$ 222"
    },
    "2": {
        "0": "AL",
        "4": "AX"
    },
    "3": {
        "0": "true",
        "4": "true"
    },
    "5": {
        "15": "$ 2.541"
    },
    "6": {
        "16": "$  "
    },
    "7": {
        "16": "#c62828"
    },
    "8": {
        "16": "2020-05-19 00:00:00"
    }
}

Now my JSON response is an associative array (JSON Object) with specific indexing (indexing is not in sequence). Does jexcel support any kind of that function?

1

There are 1 best solutions below

0
Paul On

Try the following code. It seems there was an error in the documentation.

<div id="spreadsheet2"></div>

<script>
    jexcel(document.getElementById('spreadsheet2'), {
        url:'/URL-TO-YOUR-JSON.json',
        columns: [
            { type:'text', width:'300px' },
            { type:'text', width:'100px' },
         ]
    });
</script>
</html>