Add row when using Data-sort attribute on Col
Add row when using Data-sort attribute on Col
seb33gel
Posts: 25Questions: 3Answers: 1
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
This discussion has been closed.
Replies
The easiest way, when using the HTML 5
data-*
attributes is to add a new row as atr
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
Thank you allan
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.
Can you link to a test case showing the problem please.
Allan
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.
Nudge. @allan, can you take a look? Even a workaround would be helpful.
Sorry - I missed your reply before. Thanks for the prod.
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