Problem with JSON nested values.

Problem with JSON nested values.

mesqueebmesqueeb Posts: 38Questions: 12Answers: 1

I have an AJAX datatable. It succesfully took AJAX JSON data but failed when I tried nested data.
The JSON data looks just fine. And I don't see my mistake with the nesting.

My page:

http://jtc.ae/?page=s_page&s_text=test&p_num=1&item_num=20

The warning:

DataTables warning: table id=dynamic_table - Requested unknown parameter 'post_meta.retail_from_usd' for row 0, column 2.

How I nest the Data:

dyn_t = $('#dynamic_table').DataTable({
        "ajax": {
            "url":ajax_dt_url,
            "dataSrc":""
        },
        "columns": [
            { "data" : "post_title" },
            { "data" : "post_meta.price_input" },
            { "data" : "post_meta.retail_from_usd" },
            { "data" : "post_meta.moq_num" },
            { "data" : "post_meta.lead_t" },
            { "data" : "post_meta.specification_txt" },
            { "data" : "id" },
        ],
});

I don't see my mistake. Could this be a bug?

Best regards,
-Luca Ban

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,912Questions: 1Answers: 10,148 Site admin

    No its not a bug. This is the data that is being returns from the server:

    [{
        "ID": "18667",
        "post_title": "test1",
        "category": "Building Materials",
        "slug": "building-materials",
        "supplier_company": null,
        "allslug": "building-materials, construction-and-industrial-machinery, all-industrial",
        "allcatname": "Building Materials, Construction & Industrial Machinery, All industrial",
        "allmetavalues": ", , ",
        "tags": false,
        "post_meta": {
            "_edit_lock": "1457059302:287",
            "_edit_last": "287",
            "sales_talk": "",
            "_sales_talk": "field_55751cb4d2867",
            "item_image01": "18668",
            "_item_image01": "field_550a3b65f0ae5",
            "item_image02": "",
            "_item_image02": "field_550a654f58b9a",
            "item_image03": "",
            "_item_image03": "field_550a657658b9b",
            "item_image04": "",
            "_item_image04": "field_554b2c7bd5de1",
            "item_image05": "",
            "_item_image05": "field_554b2ca3d5de2",
            "specification_txt": "aoeeo:aoe,*,",
            "_specification_txt": "field_5509476ce1d89",
            "description_txt": "",
            "_description_txt": "field_554b2b48d5ddf",
            "price_range": "",
            "_price_range": "field_5583c00a2d35d",
            "p_cond": "EXW",
            "_p_cond": "field_556fa8aefe7bf",
            "moq": "",
            "_moq": "field_556fa92cfe7c0",
            "lead_t": "",
            "_lead_t": "field_556fa948fe7c1",
            "input_comp": "",
            "_input_comp": "field_56a1e1fd2e8b7"
        },
        "img_src": ["http:\/\/jtc.ae\/pre\/wp\/wp-content\/uploads\/2016\/03\/DSC079481-190x107.jpg", 190, 107, true],
        "sql_search_count": "1"
    }]
    

    As you can see, there is no retail_from_usd property in the post_meta object. DataTables is telling you exactly what the error is :-)

    Allan

  • mesqueebmesqueeb Posts: 38Questions: 12Answers: 1

    Hey allan,
    Can i set the field to blank if the value doesn't exist inside postmeta?

  • allanallan Posts: 61,912Questions: 1Answers: 10,148 Site admin
    Answer ✓

    Sure - use columns.defaultContent.

    Allan

This discussion has been closed.