Unable to find row identifier

Unable to find row identifier

DominikFaustDominikFaust Posts: 4Questions: 1Answers: 0

Hi,

i currently try to implement the data table (with editor). It works fine, but now i got an error "Unable to find row identifier". I'm new in java script and i have no idea why my code isnt working.

If i select an item and click the edit or delete button i got this error.

http://debug.datatables.net/odexev

Greatings

Dominik

This question has an accepted answers - jump to answer

Answers

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

    I presume that the unique identifier in each row is in your Id parameter? If so, use the idSrc option to tell Editor that is where it is.

    Allan

  • DominikFaustDominikFaust Posts: 4Questions: 1Answers: 0

    Hi Allan,

    based on this example, i dont need to set the idSrc. Or am i wrong?

    https://editor.datatables.net/examples/advanced/REST.html

    If i set the idSrc the same error occurs. Here is my complete data table.

    $(document).ready(function () {
        editor = new $.fn.dataTable.Editor({
            ajax: function (method, url, data, success, error) {
                if (data.data[0].Short == '0' || data.data[0].Short == '' || data.data[0].Short == undefined || data.data[0].Short == null) {
                    data.data[0].Short = 'null';
                }
                if (data.data[0].LabelFor == '0' || data.data[0].LabelFor == '' || data.data[0].LabelFor == undefined || data.data[0].LabelFor == null) {
                    data.data[0].LabelFor = 'null';
                }
                if (data.action === 'create') {
                    $.ajax({
                        url: "http://localhost:8051/Services/TermService.svc/Rest/set/BusinessJson/" + data.data[0].Name + "/" + data.data[0].Short + "/" + data.data[0].Lcid + "/" + data.data[0].LabelFor,
                        dataType: "json",
                        success: function (json) {
                            var parsedData = $.parseJSON(json.CreateTableRowShortJsonResult);
                            if (parsedData.data) {
                                $('#businessTable').DataTable().ajax.reload();
                                success(parsedData);
                            }
                            else {
                                alert(parsedData.error)
                                error();
                            }
                        },
                        error: function () {
                            alert("Error: Request failed.");
                            error();
                        }
                    });
                }
                if (data.action === 'edit') {
    
                }
            },
            table: "#businessTable",
            fields: [{
                label: "Name:",
                name: "Name"
            }, {
                label: "Short:",
                name: "Short"
            }, {
                label: "Lcid:",
                name: "Lcid",
                type: "radio",
                options: [
                    { label: "Deutsch", value: 1031 },
                    { label: "English", value: 1033 }
                ]
            }, {
                label: "Label For:",
                name: "LabelFor"
            }
            ]
        });
    
        $('#businessTable').DataTable({
            dom: "Bfrtip",
            ajax: function (data, callback, settings) {
                $.ajax({
                    url: 'http://localhost:8051/Services/TermService.svc/Rest/get/BusinessJson',
                    success: function (data) {
                        var parsedData = $.parseJSON(data.TableAsJsonResult);
    
                        var parsedBusinessData = { data: parsedData.Data.Business }; // Need to create a object cause the table framework need the data attribute
    
                        callback(parsedBusinessData);
                    }
                });
            },
            columns: [
                    { data: "Id" },
                    { data: "Name" },
                    { data: "Short" },
                    { data: "TermId" },
                    { data: "Lcid" },
                    { data: "LabelFor" },
            ],
            select: true,
            buttons: [
                    { extend: "create", editor: editor },
                    { extend: "edit", editor: editor },
                    { extend: "remove", editor: editor }
            ]
        });
    });
    
  • DominikFaustDominikFaust Posts: 4Questions: 1Answers: 0

    Push

  • kthorngrenkthorngren Posts: 20,276Questions: 26Answers: 4,765

    I had this same problem when first starting with Datatables. By default DT looks for DT_RowId to be returned in JSON from the server. Editor uses this field as the unique row ID. If you don't return DT_RowId then, like Allan mentioned, you will need to use idSrc: "Id" in your Editor config.

    Kevin

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

    Yup - what Kevin said!

    DataTables has the ability to put DOM ids on rows automatically using the rowId option. By default that is DT_RowId.

    Editor needs to be able to tell the server what row it is editing with a unique id. That is controlled by its rowId option - also DT_RowId by default.

    Typically you would want to sent them both to be the same value.

    The fact that you are using REST doesn't make any different to the id aspect. Editor still needs to be able to tell the server what row is being edited / deleted, and that comes from the id.

    Allan

  • DominikFaustDominikFaust Posts: 4Questions: 1Answers: 0

    Now i got it. In my example i have to set both rowId and srcId to "Id" and it works. Thank you for your Help allen and kthrongren.

This discussion has been closed.