What are the column names in a JSON file matched with? Can column indices be used instead?

What are the column names in a JSON file matched with? Can column indices be used instead?

Boilermaker80Boilermaker80 Posts: 19Questions: 6Answers: 0

Must the columns in DataTables be named using columns : [col1, col2, ...] in order to be loaded from a JSON file? Is it possible to use column indices instead?

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947

    You can use arrays or objects. This page describes the data structures:
    https://datatables.net/manual/data/#Data-source-types

    Here are a couple ajax examples that show the difference between arrays and objects:
    https://datatables.net/examples/ajax/simple.html
    https://datatables.net/examples/ajax/objects.html

    This should get you started. Please post further questions.

    Kevin

  • Boilermaker80Boilermaker80 Posts: 19Questions: 6Answers: 0

    Thanks, but that's not what I'm asking. These examples contain data of the form label : value. Presumably "label" refers to a column name, though I haven't found an example that says that. Columns can also be referred to by number. What would that look like in JSON? 0 : value?

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947
    Answer ✓

    These examples contain data of the form label : value. Presumably "label" refers to a column name

    Correct. If you look at the Objects section of the above link it shows an example of this. Also when you look at the two examples they default to showing the Javascript code. Click on the Ajax tab and you will see the data and data structure.

    This example I provided is an array structure not object based:
    https://datatables.net/examples/ajax/simple.html

    Maybe you can post a more specific example of the data structure you want to use and we can help from there.

    Kevin

This discussion has been closed.