Editing tables with array-based data

Editing tables with array-based data

fabianrottfabianrott Posts: 30Questions: 1Answers: 0

Hi!

I'm trying to reproduce an error that came up while adding inline editing functionality to an existing project. The problem seems to be that the backend delivers data in array form instead of keys and values. This worked fine with DataTables previously, but now I'm having trouble understanding, why the following code produces Unable to find row identifier as an error, whenever I click on a cell.

var editor;
$(function() {
    editor = new $.fn.dataTable.Editor( {
        ajax: {
                url: "ajax_editor"
            },
        table: "#table-view",
        fields: [ {
                label: "First name:",
                name: "0"
            }, {
                label: "Last name:",
                name: "1"
            }, {
                label: "Position:",
                name: "2"
            }
        ],
        idsrc: "0"
    } );


    // Activate an inline edit on click of a table cell
    $('#table-view').on( 'click', 'tbody td:not(:first-child)', function (e) {
        editor.inline( this );
    } );

    var table = $('#table-view').DataTable( {
        dom: "Bfrtip",
        columns: [
            {
                data: null,
                defaultContent: '',
                className: 'select-checkbox',
                orderable: false
            },
            { data: "0" },
            { data: "1" },
            { data: "2" }
        ],
        rowId: '0',
        select: {
            style:    'os',
            selector: 'td:first-child'
        },
        buttons: [
            { extend: "create", editor: editor },
            { extend: "edit",   editor: editor },
            { extend: "remove", editor: editor }
        ],
        data: [
            [
                "Tiger",
                "Nixon",
                "System Architect"
            ],
            [
                "Garrett",
                "Winters",
                "Accountant"
            ]
        ]
    } );
});

By the way: I was trying to get the example code from the DataTables Documentation running in DataTables live, but I don't get to see the data.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,823Questions: 1Answers: 10,129 Site admin
    Answer ✓

    idsrc: "0"

    Should be:

    idSrc: "0"
    

    See idSrc. Javascript is case sensitive.

    Allan

  • fabianrottfabianrott Posts: 30Questions: 1Answers: 0

    Ouch!

    Thanks, I guess that means I can go solve my real problem now...

This discussion has been closed.