Uncaught TypeError: Cannot read properties of undefined (reading 'attach') at a.mb [as inline]

Uncaught TypeError: Cannot read properties of undefined (reading 'attach') at a.mb [as inline]

pierantonio.bonatopierantonio.bonato Posts: 1Questions: 1Answers: 0

After inline update row it appear on console this error

Uncaught TypeError: Cannot read properties of undefined (reading 'attach')
at a.mb [as inline]
:

This is my Javascript code:

function loadInventario() {

        //EDITOR
        editorInventario = new $.fn.dataTable.Editor({
            ajax: {
                create: {
                    processing: true,
                    serverSide: false,
                    type: "GET",
                    url: '../Control/ws_Inventario.asmx/addInventario',
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (data, statusText, resObject) {
                        //alert('ok')
                        var jsonData = resObject.responseJSON;
                        if (jsonData["status"] != "OK") {
                            alert(jsonData["status"]);
                        }
                    },
                    error: function (xhr, status, error) {
                        alert("KO")
                        var errorMessage = xhr.status + ': ' + xhr.statusText
                        alert('Error - ' + errorMessage);
                    },
                    complete: function () {
                        $('#tblInventario').DataTable().clear();
                        $('#tblInventario').DataTable().ajax.reload();
                    }
                },
                edit: {
                    type: "GET",
                    url: '../Control/ws_Inventario.asmx/editInventario',
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (data, statusText, resObject) {
                        var jsonData = resObject.responseJSON;
                        if (jsonData["status"] != "OK") {
                            alert(jsonData["status"]);
                        }
                    },
                    error: function (xhr, status, error) {
                        if (xhr.status != 0) {
                            var errorMessage = xhr.status + ': ' + xhr.statusText
                            alert('Error - ' + errorMessage);
                        }
                    },
                    complete: function () {
                        $('#tblInventario').DataTable().clear();
                        $('#tblInventario').DataTable().ajax.reload();
                    }
                },
                remove: {
                    type: "GET",
                    url: '../Control/ws_Inventario.asmx/removeInventario',
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (data, statusText, resObject) {
                        var jsonData = resObject.responseJSON;
                        if (jsonData["status"] != "OK") {
                            alert(jsonData["status"]);
                        }
                    },
                    error: function (xhr, status, error) {
                        if (xhr.status != 0) {
                            var errorMessage = xhr.status + ': ' + xhr.statusText
                            alert('Error - ' + errorMessage);
                        }
                    },
                    complete: function () {
                        $('#tblInventario').DataTable().clear();
                        $('#tblInventario').DataTable().ajax.reload();
                    }
                }
            },
            table: '#tblInventario',
            idSrc: 'CodiceIngobbioAS',
            fields: [
                { label: 'DataInventario', name: 'DataInventario' },
                { label: 'CodStabilimento', name: 'CodStabilimento' },
                { type: 'select', label: 'Cod.Ingobbio AS', name: 'CodiceIngobbioAS', options: codengobbi_options },
                { label: 'Quantita', name: 'Quantita' }
            ]
        });
        editorInventario.on('initCreate', function (e, action) {

            editorInventario.field('DataInventario').val($('#dtInventario').val())
            editorInventario.field('CodStabilimento').val($('#selStab').val())
            return true;

        });
        editorInventario.on('initRemove', function (e, action) {

            editorInventario.field('DataInventario').val($('#dtInventario').val())
            editorInventario.field('CodStabilimento').val($('#selStab').val())
            return true;

        });
        editorInventario.on('initSubmit', function (e, action) {

            if (action == "edit") {
                editorInventario.field('DataInventario').val($('#dtInventario').val())
                if (editorInventario.field('Quantita').val() === '') {
                    editorInventario.field('Quantita').error('Valorizzare il campo');
                    return false;
                }
                return true;
            } else {
                if (action == "create") {
                    if (editorInventario.field('Quantita').val() === '') {
                        editorInventario.field('Quantita').error('Valorizzare QUANTITA');
                        return false;
                    }
                } else {
                    return true
                }
            }
        });

        //TABLE
        $('#tblInventario').DataTable().destroy();
        $('#tblInventario tbody').html("<tr><td></td></tr>")

        $('#tblInventario').on('click', 'tbody td.editable', function (e) {
            //editorInventario.inline(this, {

            editorInventario.inline(tblInventario.cell(this).index(), {
                onBlur: 'submit',
                submit: 'allIfChanged'
            });
        });

        var tblInventario = $('#tblInventario').DataTable({
            processing: true,
            serverSide: false,
            pageLength: 1000,
            ajax:
            {
                type: "POST",
                dataType: 'json',
                url: "../Control/ws_Inventario.asmx/ListaInventario",
                data:
                {
                    'DataInventario': $('#dtInventario').val(),
                    'CodStabilimento': $('#selStab').val()
                },
                dataSrc: function (json) {
                    //alert("Done!");

                    return json.data;
                },
                error: function (xhr, status, error) {
                    var errorMessage = xhr.status + ': ' + xhr.statusText
                    alert('Error - ' + errorMessage);
                }
            },
            dom: '<"H"rfB>t<"F"i>',
            columns: [
                { data: "CodStabilimento", className: "text-left" },
                { data: "Stabilimento", className: "text-left" },
                { data: "CodiceIngobbioAS", className: "text-left" },
                { data: "CodiceIngobbio", className: "text-left" },
                { data: "Ingobbio", className: "text-left text-nowrap" },
                {
                    data: "Quantita", className: "editable dt-body-right", render: function (data, type, row) {
                        if (data === 0 && row.DataUltimoInventario === null) {
                            return '';
                        } else {
                            return data.toLocaleString('it-IT');
                        }
                        return data;
                    }
                },
                { data: "Giacenza", className: "dt-body-right text-nowrap", render: $.fn.dataTable.render.number('.', '', 0, '') },
                { data: "DataUltimoInventario", className: "dt-body-right text-nowrap", render: $.fn.dataTable.render.moment('DD/MM/YYYY') },
                {
                    data: null, className: "dt-center editor-delete", render: function (data, type, row) {

                        if (data.DataUltimoInventario === null) {
                            return '';
                        } else {
                            return '<i class="fa fa-trash"></i>';
                        }
                        return data;
                    }, orderable: false
                }

            ],
            select: false,
            buttons: [
                { extend: 'create', editor: editorInventario }
            ],
            language: {
                url: '../resources/it.json'
            },
            fnRowCallback: function (nRow, aData, iDisplayIndex, iDisplayIndexFull) {
                if (aData.Quantita === 0 && aData.DataUltimoInventario === null) {
                    $(nRow).find('td:eq(5)').css('background-color', '#ffc107');
                }

            }
        })
    }

Answers

  • allanallan Posts: 61,438Questions: 1Answers: 10,052 Site admin

    Could you give me a link to the page showing the issue please? It isn't immediately obvious from the code above what is going wrong.

    Thanks,
    Allan

Sign In or Register to comment.