Add row when using Data-sort attribute on Col

Add row when using Data-sort attribute on Col

seb33gelseb33gel Posts: 25Questions: 3Answers: 1
edited July 2014 in Free community support

Hello

On my progect I use data-sort attribute in my table. All work fine but when I want to add row I get error message.
When I remove data-sort attribute, all worked fine.

http://live.datatables.net/butazom/1/

What is the best way to add Row with data-* html 5 attribute on col.

Many Thanks

Replies

  • allanallan Posts: 61,667Questions: 1Answers: 10,096 Site admin

    The easiest way, when using the HTML 5 data-* attributes is to add a new row as a tr element: http://live.datatables.net/butazom/2/edit . Otherwise you need to add the data using the format that DataTables uses internally so that it has both the display and search data (since using the array format you had, it doesn't have that information).

    If you want to see that object format, use the data() method and inspect the data in the console.

    Allan

  • seb33gelseb33gel Posts: 25Questions: 3Answers: 1

    Thank you allan

  • dramentoldramentol Posts: 1Questions: 0Answers: 0

    Hi Allan,

    I'm using the object format with the data() method and works great if there are other rows in the table, but when the table has no rows it displays '[object Object]' as the value on the table.

  • allanallan Posts: 61,667Questions: 1Answers: 10,096 Site admin

    Can you link to a test case showing the problem please.

    Allan

  • ArthurNArthurN Posts: 2Questions: 0Answers: 0

    I am running into the same issue. Here is a jsFiddle showing the problem:
    http://jsfiddle.net/97qpagbj/
    (Click the "Add row" button at the top)

    If, however, the DataTable has some data already in it, then everything works great:
    http://jsfiddle.net/4uujj56r/1/

    It's as if DataTables doesn't know what kind of data format it's supposed to be looking at.

  • ArthurNArthurN Posts: 2Questions: 0Answers: 0

    Nudge. @allan, can you take a look? Even a workaround would be helpful.

  • allanallan Posts: 61,667Questions: 1Answers: 10,096 Site admin

    Sorry - I missed your reply before. Thanks for the prod.

    It's as if DataTables doesn't know what kind of data format it's supposed to be looking at.

    That is exactly the case. When using attributes DataTables will automatically modify the data source reader properties for the row so as to be able to read them. With no data int he table, it can't do that.

    However you can configure it in that manner: http://jsfiddle.net/97qpagbj/1/

    That is basically what DataTables is doing internally.

    Allan

This discussion has been closed.