table.row.add() with defined columns

table.row.add() with defined columns

montoyammontoyam Posts: 568Questions: 136Answers: 5
edited November 2021 in DataTables 1.10

why when I define a table with columns is the row.add() adding each data element to each cell?

in the example below, you will see table1 is displaying incorrectly.

http://live.datatables.net/sapasuxu/1/edit

I'm guessing the syntax needs to be different for the row.add()???

RequestDetailTable.row.add([0, value.RESPONSIBILITY_ID, value.RESPONSIBILITY_NAME]).draw();

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,341Questions: 26Answers: 4,954
    edited November 2021 Answer ✓

    For Table1 you are defining columns.data as null for all the columns. The docs state this when using null:

    Use the original data source for the row rather than plucking data directly from it

    This is why you are seeing the full row of data in the 2nd and 3rd columns. You could use columns.render to extract the particular data you want.

    A better option, since your row data structure is objects, is to use columns.data to define the columns. Its much easier and you can add all the rows at once. See Table3 of the updated example:
    http://live.datatables.net/sapasuxu/2/edit

    Kevin

  • montoyammontoyam Posts: 568Questions: 136Answers: 5

    ah, I always thought if a value was in columns.data it was going to look for a data source, like from an ajax call. good to know.

    thanks.

Sign In or Register to comment.