Unable to find row identifier - Error on editor

Unable to find row identifier - Error on editor

AdviceITAdviceIT Posts: 2Questions: 1Answers: 0

Hi

I have created a table with 5 columns. I use:

var t = $('#tblvia').DataTable();
        t.row.add( [
            row[0],
            row[1],
            row[2],
            row[3],
            row[4]
        ] ).draw(false);

Which adds the new row perfectly.

I want to be able to utilise the features from Editor for inline editing the content of this table. The table is dynamic and not pulled from a data source.

I have setup my table and also setup the Editor as follows:

editor = new $.fn.dataTable.Editor( {
        table: "#tblvia",
        idSrc:  "id",
        fields: [ {
                label: "Postal Name:",
                name: "postal_name"
            }, {
                label: "Address 1:",
                name: "address1"
            }, {
                label: "Address 2:",
                name: "address2"
            }, {
                label: "Town:",
                name: "town"
            }, {
                label: "Postcode:",
                name: "postcode"
            }
        ]
    } );

    $('#tblvia').DataTable({
        columns: [
            {name: "postal_name"},
            {name: "address1"},
            {name: "address2"},
            {name: "town"},
            {name: "postcode"}
        ],
        "createdRow": function( row, data, dataIndex ) {
            $(row).attr('id', dataIndex);
          }
    });

But I keep getting "Unable to find row identifier" error.

Can someone please shed some light on this.

Thank you.

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,569Questions: 26Answers: 4,996

    This tech note will explain the meaning and how to fix:
    https://datatables.net/manual/tech-notes/14

    Kevin

  • allanallan Posts: 63,850Questions: 1Answers: 10,519 Site admin
    Answer ✓

    So the problem here is that you have added the data to the DataTable as an array, but the columns.data and fields.name properties used for DataTables and Editor are expecting an object.

    You either need to decide to use all objects, or all arrays. I'd suggest objects! Then it would be:

            t.row.add( {
              postal_name: row[0],
              ...
            } );
    

    assuming that row is an array which it appears to be.

    Allan

  • AdviceITAdviceIT Posts: 2Questions: 1Answers: 0

    Thank you Allan and Kevin, I understand now and have it working.

    :smiley:

This discussion has been closed.