rows.add() spliting up my data

rows.add() spliting up my data

AndaniAndani Posts: 1Questions: 0Answers: 0

Good Day

I am trying to add rows to datatable using jquery.
table.rows.add(['Andani']).draw();

The added string "Andani" is being split across for columns.
You will get the "A" in the first column, "n" in the second column, "d" in the third column, and so on an so on.

What could I be doing wrong?

Replies

  • Tom (DataTables)Tom (DataTables) Posts: 139Questions: 0Answers: 26
    edited June 2016

    Hi

    When using row.add() expects either an object or array to be passed in so it can created the row with the data it has received, the data must match the number of columns in the table.

    So you could either pass in an array of data that matches the column count of your table such as (if your table has 6 columns)

    table.row.add([1,2,3,4,5,6]).draw();
    

    or specify each column explicitly such as

    table.row.add( {
        "col1": "data1",
        "col2": "data2",
        "col3": "data3",
        "col4": "data4",
        "col5": "data5",
        "col6": "data6"
    }).draw(); 
    

    If you want to add multiple rows at a time then you can also use rows.add()

    Thanks

    Tom

This discussion has been closed.