Datatable json, use only specific key

Datatable json, use only specific key

mashaprshmashaprsh Posts: 2Questions: 1Answers: 0

For example, I have a json that looks like this :

{
    "perusahaan": {
        "nomorLaporan": "NO-001",
        "fasilitas": {
            "kreditPembiayan": [
                {
                    "ljk": "510",
                    "ljkKet": "BANK NATIONALNOBU",
                    "jumlahHariTunggakan": "0",
                    "nilaiProyek": "20000000000",
                    "plafonAwal": "20000000000",
                    "plafon": "20000000000"
                },
                {
                    "ljk": "503",
                    "ljkKet": "BANK NATIONALNOBU",
                    "jumlahHariTunggakan": "0",
                    "nilaiProyek": "15000000000",
                    "plafonAwal": "15000000000",
                    "plafon": "15000000000"
                },
                {
                    "ljk": "563",
                    "ljkKet": "BCA",
                    "jumlahHariTunggakan": "0",
                    "nilaiProyek": "15000000000",
                    "plafonAwal": "15000000000",
                    "plafon": "15000000000"
                },
                {
                    "ljk": "509",
                     "ljkKet": "BCA",
                      "jumlahHariTunggakan": "0",
                      "nilaiProyek": "15000000000",
                      "plafonAwal": "15000000000",
                     "plafon": "15000000000"
                 }
            ]
        }
    },
"perusahaan": {
        "nomorLaporan": "NO-002",
        "fasilitas": {
            "kreditPembiayan": [
                {
                    "ljk": "511",
                    "ljkKet": "BANK NATIONALNOBU",
                    "jumlahHariTunggakan": "0",
                    "nilaiProyek": "20000000000",
                    "plafonAwal": "20000000000",
                    "plafon": "20000000000"
                },
                {
                    "ljk": "563",
                    "ljkKet": "BANK NATIONALNOBU",
                    "jumlahHariTunggakan": "0",
                    "nilaiProyek": "15000000000",
                    "plafonAwal": "15000000000",
                    "plafon": "15000000000"
                },
                {
                    "ljk": "566",
                    "ljkKet": "BCA",
                    "jumlahHariTunggakan": "0",
                    "nilaiProyek": "15000000000",
                    "plafonAwal": "15000000000",
                    "plafon": "15000000000"
                },
                {
                    "ljk": "502",
                     "ljkKet": "BCA",
                      "jumlahHariTunggakan": "0",
                      "nilaiProyek": "15000000000",
                      "plafonAwal": "15000000000",
                     "plafon": "15000000000"
                 }
            ]
        }
    }
}

How can I acces the kreditPembiayan and use it for datatable. I mean, it's easy if the json only kreditPembiayan I can just literally using this code :

mytable_1 = $('#mytable_1').DataTable({
                'processing': true,
                "ajax": {
                    "url": "url_to_my_json",
                    "dataSrc": "",
                },
                "columns": [
                    {data: 'ljk'},
                    {data: 'ljkKet'},
                    {data: 'jumlahHariTunggakan'},
                    {data: 'nilaiProyek'},
                    {data: 'plafonAwal'},
                    {data: 'plafon'},
                ],
            });

Any Idea ???

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599
    Answer ✓

    As you say, that's not supported. What you would need to do is to have a function for ajax.dataSrc, and flatten out your JSON structure and return that instead.

    Colin

  • mashaprshmashaprsh Posts: 2Questions: 1Answers: 0

    Owh so that is not supported, okay thanks for answering my question..

This discussion has been closed.