Unable to generate rows from Json file

Unable to generate rows from Json file

lewoyylewoyy Posts: 4Questions: 1Answers: 0

I regret to ask as I feel like I am just doing something incredibly wrong/stupid. I have a JSON file with 5978 assets stored in it (querying a database). I want to be able to show the assets in a DataTable. I cannot for the life of me get the table to generate.

I have added images below, firstly of the JS to generate the table.

The second image shows how the JSON is formatted, I have shortened it to just two of the 5978 assets to make it readable.

If anybody knows what I am doing wrong please feel free to help! Apologies, somebody who has little coding experience and just wants to create something cool! :)


This question has an accepted answers - jump to answer

Answers

  • lewoyylewoyy Posts: 4Questions: 1Answers: 0

    Just incase this is of any use!

  • kthorngrenkthorngren Posts: 21,443Questions: 26Answers: 4,974
    edited November 17 Answer ✓

    You have data: asset_Tag defined but in JSON its asset_tag. Its case sensitive so change to data: asset_tag. But that is not causing the error.

    You need to define the ajax.dataSrc within the ajax option. Should look more like this:

        ajax: {
            url: 'data.json',
            dataSrc: 'rows'
        },
        columns: [
        .....
    

    This might cause the error. Another cause could be a mis-match in the number of columns defined in the thead of the table and the number defined by columns.data. You defined 6 in columns.data so the thead should have 6 th elements.

    If this doesn't help then we will need to see a link to a test case replicating the error to help debug.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • lewoyylewoyy Posts: 4Questions: 1Answers: 0

    Hi Kevin,

    noticed the data: asset_Tag as soon as I posted. I cant believe I have stared at this all night and you have fixed this in an instance. wrapped the datasrc and url in Ajax and it works, legend!

  • lewoyylewoyy Posts: 4Questions: 1Answers: 0

    Hi @kthorngren ,

    Any idea why this may only be displaying 500 entries, when there is 5978 items in the JSON file I am pulling in? Nothing in my console to suggest why. I am not sure how I would provide a test case as I cant add the json file?

  • kthorngrenkthorngren Posts: 21,443Questions: 26Answers: 4,974
    edited November 18

    Datatables won't truncate the records received. Start by using the browser's network inspector tool to view the JSON response. How many records are in the response?

    My guess is 500 so you will need to debug the server script to determine why its returning only 500 records.

    Possibly they aren't all in the rows object.

    Kevin

  • kthorngrenkthorngren Posts: 21,443Questions: 26Answers: 4,974

    Thanks for PM'ing the test case link. Looking at the browser's network inspector tool the server is responding with only 500 rows of data:

    Possibly there is some limit imposed in your server script. You will need to debug the server script to determine why it is returning only 500 rows. The client side Datatables is not doing anything that will cause the server to return only 500 of the 5978 records in the JSON data source.

    Kevin

Sign In or Register to comment.