1

I am trying to use an array of objects as an input to Datatables. Each object in the array I want to be a row in the table. Is there a way of inserting the data without specifying the column names?

var table = $('#data_table_test').DataTable( {
    "data": data,
    "columns": [
        { "data": "GENE_NAME" },
        { "data": "FDR"},
    ],
    dom: 'Bfrti',
    deferRender: true,
    scrollY: 420,
    scrollX: true,
    scroller: true,
    buttons: [
        'excel','csv'
    ],
    order: [],
} );

This works because I am specifying the column names, but I can't figure out a way to insert the data without using the column names.

2

1 Answer 1

1

If the only issue is that you want to avoid naming the column, you could define the number of columns with just an empty definition

You could build the table definition in javascript based on your data and then pass it to the datatables initialization:

var tableDef = [ {}, {} ];

"columns": tableDef

I made a quick fiddle just to see if the idea works: https://jsfiddle.net/zyat1q2p/1/

Sign up to request clarification or add additional context in comments.

3 Comments

Unfortunately, the number of columns won't be the same for every table
What if you built a javascript variable to become your columns definition?
yea I think I might have to go that route.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.