How to use Editor.edit() without AJAX with custom id?
How to use Editor.edit() without AJAX with custom id?
Link to test case: http://live.datatables.net/surabope/1/edit
Error messages shown: Uncaught Unable to find row identifier For more information, please refer to https://datatables.net/tn/14
Description of problem: I need to add new rows and edit them programmatically with Editor. Since I want to use an UUID as row id, I added rowId
.
Then I wanted to use the following:
var rows = table.DataTable().rows([0, 1]).indexes();
editor.edit(rows, false);
But I get the error aforementioned. How to define a custom id to be able to edit using it with editor?
This question has an accepted answers - jump to answer
Answers
Your test case doesn't run properly plus its a bit confusing because you are adding objects but you aren't defining that with
columns.data
. Assuming you have defined this withcolumns.data
you need to set theidSrc
option as described in the troubleshooting link: https://datatables.net/manual/tech-notes/14Kevin
I should have mentioned outside the title the fact that I don't use AJAX (since the title is not displayed completely). I get data from WebSocket that I want to add with
row.add()
. I already checked https://datatables.net/manual/tech-notes/14 but it seems to be for AJAX source.To add rows manually, I thought I can just delete line with
ajax
. Am I wrong?I edited the test case but I'm sorry I couldn't reproduce the message since I face in the test case:
Uncaught ReferenceError: alert is not defined
.I fixed the "noise issue"
Uncaught ReferenceError: alert is not defined
in a new test case.So I have been able to reproduce exactly:
Uncaught Unable to find row identifier For more information, please refer to https://datatables.net/tn/14
.I wouldn't say that. You need to define the
idSrc
if its different than the default ofDT_RowId
.I updated your test case. Used
columns.data
since you are using objects to solve this error:Added
rowId
andidSrc
to useuuid
to solve this error:You can just use:
Instead of breaking out each object element, ie:
Then added this to show the edit now works:
http://live.datatables.net/sabosudi/1/edit
Kevin
Super Kevin, thank you so much for this clear answer that even simplified the way of proceeding.
Thanks Kevin for this clear answer. Actually I broke out each object element, ie:
because I needed to put some calculated values (from the DOM).
Would you be able to update the example using this way?
Just remove what I added and uncomment the row.add() you want to use.
Kevin
It's exactly what I thought, but when I do it carefully I get
Uncaught ReferenceError: alert is not defined
. Here is the result.For the changes we made it needs to be in object notation not array. It is much easier to use Datatables with objects rather than arrays. See this example:
http://live.datatables.net/xaloxomu/1/edit
However if you want to use arrays the
e-option
idSrc` docs state you can use an integer. However that doesn't seem to be working in this example:http://live.datatables.net/nagaxuju/1/edit
Maybe @allan or @colin can comment on why.
Kevin