Using row with server side processing
Using row with server side processing
I have read posts saying this is a bad idea but i'm pretty sure I have a good use case.
Currently (without DT) I have a table that updates live, when the database gets a new row it sends a websocket message to the tables javascript which appends a new row. I'd like to do the same with DT but the only way i can get it to work is to fresh the whole table when a new row comes in.
Is there a way to simply add a new row with javascript? I have tried .draw(false) but doesn't seem to work.
Thanks.
This question has an accepted answers - jump to answer
Answers
Hi @Jleagle ,
row.add()
will add a new row to a table, like this here.Cheers,
Colin
I am asking specifically for server side processing enabled. When this is enabled and you add a row, the table refreshes and it is no longer there. I'd like to add a row and no ajax happen, no anything, just add a new row in.
If you're not using Editor, you'll have to add it to the table yourself. Given you want it on the server side, you just send the row data back in an Ajax statement, and add it to your remote data source.
No - this is not currently possible in DataTables. When server-side processing is enabled, then any draw will always get new data from the server for the current page. When server-side processing is enabled, DataTables is designed as a view only component. It is not a data store (other than what it currently needs to show).
For example - you add your new row, but where should it go in the table, and should it be filtered out based on the current filter options? That is something that would have to be decided by server-side processing when
serverSide
is enabled.Allan
colin: It's not that i want it on the server-side, it's already been added to my database and just want to reflect that live without querying the table again (using websockets)
allan: Thanks for the answer! I managed to get what i wanted in the end by writing some non DT code. The websocket will send the same data array that DT accepts, i can then pass it through the same "render" & "createdCell" callbacks that are in my "columnDefs" array and build up a row manually and prepend it to the table.
Thanks!