datatablesjquery-datatables-editor

Unable to automatically determine field from source


Why am i getting this error:

Unable to automatically determine field from source

This is my Editor:

fields: [ 
        {
            label: "Art:",
            name: "art"
        }, 
        {
            label: "Benämning:",
            name: "name"
        }, 
        {
            label: "Antal:",
            name: "balance"
        },
        {
            label: "Enhet:",
            name: "unit"
        }
    ]

This is my Datatable:

columns: [
        {data: null,
            defaultContent: '',
            className: 'select-checkbox',
            orderable: false,
            searchable: false
        },
        { data: "art"},
        { data: "name" },
        { data: "balance", searchable: false },
        { data: "unit", orderable: false },
        { data: null,
            targets: -1,
            defaultContent: '<button type="button" class="btn btn-sm btn-primary transactionModalBtn" ">+ -</button>', //data-bs-toggle="modal" data-bs-target="#transactionModal
            orderable: false,
            searchable: false
        }
    ],

The error accours when i click on the last column td.
That column should have buttons in it and should not be a editable cell.

Do i need to disable edit on that column? How can i do that?

I've tried to add a field to the editor, but that wont help and that is not in the editor example: https://datatables.net/examples/ajax/null_data_source.html

Is the problem im using columns instead os columnDefs?

This is the event:

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

Solution

  • Solution was in the click event:

    // Activate an inline edit on click of a table cell
    $('#inventory').on( 'click', 'tbody td:not(.noEdit)', function (e) {
            editor.inline( table.cell( this ).index(), {
                    onBlur: 'submit'
            } );
    });
    

    I've changed td:not(:first-child) to above, and then gave the td a className.

    { data: null,
                targets: -1,
                defaultContent: '<button type="button" class="btn btn-sm btn-primary transactionModalBtn" ">+ -</button>', //data-bs-toggle="modal" data-bs-target="#transactionModal
                className: 'noEdit',
                orderable: false,
                searchable: false
            }