How to use Editor.edit() without AJAX with custom id?

How to use Editor.edit() without AJAX with custom id?

richard.carree.com@gmail.comrichard.carree.com@gmail.com Posts: 23Questions: 7Answers: 0
edited February 2021 in Free community support

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

  • kthorngrenkthorngren Posts: 21,174Questions: 26Answers: 4,923

    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 with columns.data you need to set the idSrc option as described in the troubleshooting link: https://datatables.net/manual/tech-notes/14

    Kevin

  • richard.carree.com@gmail.comrichard.carree.com@gmail.com Posts: 23Questions: 7Answers: 0
    edited February 2021

    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.

  • richard.carree.com@gmail.comrichard.carree.com@gmail.com Posts: 23Questions: 7Answers: 0
    edited February 2021

    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.

  • kthorngrenkthorngren Posts: 21,174Questions: 26Answers: 4,923

    I already checked https://datatables.net/manual/tech-notes/14 but it seems to be for AJAX source.

    I wouldn't say that. You need to define the idSrc if its different than the default of DT_RowId.

    I updated your test case. Used columns.data since you are using objects to solve this error:

    DataTables warning: table id=example - Requested unknown parameter '4' for row 0, column 4. For more information about this error, please see http://datatables.net/tn/4

    Added rowId and idSrc to use uuid to solve this error:

    Uncaught Unable to find row identifier For more information, please refer to https://datatables.net/tn/14

    You can just use:

    table.row.add(row).draw();
    

    Instead of breaking out each object element, ie:

    table.row.add([
        row.uuid,
    ....
    

    Then added this to show the edit now works:

      var rows = table.rows([0]).indexes();
      editor.edit(rows);
    

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

    Kevin

  • richard.carree.com@gmail.comrichard.carree.com@gmail.com Posts: 23Questions: 7Answers: 0
    edited February 2021

    Super Kevin, thank you so much for this clear answer that even simplified the way of proceeding.

  • richard.carree.com@gmail.comrichard.carree.com@gmail.com Posts: 23Questions: 7Answers: 0

    Thanks Kevin for this clear answer. Actually I broke out each object element, ie:

    table.row.add([
        row.uuid,
    ...
    

    because I needed to put some calculated values (from the DOM).

    Would you be able to update the example using this way?

  • kthorngrenkthorngren Posts: 21,174Questions: 26Answers: 4,923

    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

  • richard.carree.com@gmail.comrichard.carree.com@gmail.com Posts: 23Questions: 7Answers: 0

    It's exactly what I thought, but when I do it carefully I get Uncaught ReferenceError: alert is not defined. Here is the result.

  • kthorngrenkthorngren Posts: 21,174Questions: 26Answers: 4,923
    Answer ✓

    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

This discussion has been closed.