Must I have every field name identified on page?

Must I have every field name identified on page?

enjoypbenjoypb Posts: 31Questions: 12Answers: 0

I have a server-side version working great. I'm now trying to build a Ajax version. I have a script that queries my data on my server, and generates (I validated it) good JSON. I do a CRON job to update the file nightly. The issue is I can't for the life of me get a single row of data (only 5k rows) to appear.

Do I have to rename the .json file as a .txt file is one question
The second question is do I have to account for every field in the JSON file? I have 75 columns but, am only wanting to display about 10 on the DataTable.

Thank you very much. Your product kicks butt and I can't wait to dig in deeper.

This question has an accepted answers - jump to answer

Answers

  • glendersonglenderson Posts: 231Questions: 11Answers: 29

    If you don't have the identical number of elements in the JSON file as you want to appear in the table, you should define the columns with a data name.

      , "columns": [
         { "data":"resourceName"}
        ,{ "data":"city"}
        ,{ "data":"state"}
        ,{ "data":"country"}
        ,{ "data":"planet"}
        ]
    

    This sets up datatTables to populate the column with the named data

     "data": [
    {
    "DT_RowId":"rowID_1",
    "DT_RowAttr":{"data-username":"castlpoint,"data-projectid":"24","data-projectionid":"708"},
    "resourceName":"My Resource name"
    ,"1":"json data I don't use"
    ,"city":"Brooklyn"
    ,"3":"more data I don't use"
    ,"state":"New York"
    ....
    },
    
  • allanallan Posts: 63,761Questions: 1Answers: 10,510 Site admin
    Answer ✓

    Its also worth pointing out that the extension of the file is irrelevant - as long as it contains valid JSON.

    We'd need to know the JSON structure to help any more than that.

    Allan

  • enjoypbenjoypb Posts: 31Questions: 12Answers: 0

    Thanks guys. I did get it to work by including every possible field available, even though I was only calling a few to display on the table. Love DataTables!

This discussion has been closed.