Uncaught TypeError: Cannot read properties of undefined (reading 'length')

Uncaught TypeError: Cannot read properties of undefined (reading 'length')

tableFan22tableFan22 Posts: 8Questions: 2Answers: 0

Hello,
I've been trying to fix this error for days, but unfortunately with no luck... I have the licenses for the editor tables from my company where I work. This is my private account.

            public ActionResult EditorTable()
                    {         
                        string dbConnection = this._configuration.GetSection("ConnectionStrings")[connection];

                        using (var db = new Database("azure", dbConnection))

                            {
                                var response = new Editor(db, "DBtable")
                                    .Model<DBtable>()
                                    .Field(new Field("Name"))
                                    .TryCatch(false)                     
                                    .Process(Request)
                                    .Data();
                                return Json(response);
                            }

                    }

            <div class = "card">
                <div class = "card-header"></div>
                <div class = "card-body">
                    <table id = "tableID" class="table">
                        <thead>
                            <tr>
                                <th>
                                    Name
                                </th>
                                <th></th>
                            </tr>
                        </thead>
                        <tfoot>
                            <tr></tr>
                        </tfoot>  
                    </table>
                </div>
                <div class = "card-footer"></div>
            </div>


            <script type="text/javascript">
                    var editor;  
                    $(document).ready(function(){
                        editor = new $.fn.dataTable.Editor ({
                            ajax: {url: "/Controller/EditorTable" , type: "POST"},
                            table: "#tableID",
                            fields: [{
                                label: "Name",
                                name: "Name"           
                                }
                            ]
                        });

                        $('#tableID').on('click', 'tbody td:not(:first-child)', function (e) {
                            editor.inline(this);
                        });

                       var table = $('#tableID').DataTable({
                        dom: "Bfrtip",
                        lengthMenu: [
                           [10, 25, 50, -1],
                           ['10 rows', '25 rows', '50 rows', 'Show all']
                        ],
                        stateSave: true,
                        ajax: "/Controller/EditorTable",

                        columns: [
                            {
                                data: null,
                                defaultContent: '',
                                className: 'select-checkbox',
                                orderable: false
                            },
                            { data: "Name"}
                        ],
                        select: {
                            style: 'os',
                            selector: 'td:first-child'
                        },
                        buttons: [
                            { extend: "create", editor: editor },
                            { extend: "edit", editor: editor },
                            { extend: "remove", editor: editor },
                            'pageLength'
                        ]
                      });
                  });
                </script>

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    At what point does the error happen? On load, edit, delete or something else? Can you show me the JSON response from the server when it does happen please?

    Thanks,
    Allan

  • tableFan22tableFan22 Posts: 8Questions: 2Answers: 0

    hi Allan, it happens directly when the data is displayed. The table says "Loading" all the time

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Thanks for the stack trace, but can you also post the response from the server, please, when this error occurs. You'll be able to get this from the network inspector for the browser,

    Colin

  • tableFan22tableFan22 Posts: 8Questions: 2Answers: 0

    hi Colin, this is the server response from the page with the editor table..

  • tableFan22tableFan22 Posts: 8Questions: 2Answers: 0

    status 101

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    That's the problem, the server should be returning valid JSON containing the data for the rows. Have you ran the PHP script on the server, as this would display the errors? Also, have you checked any server-side logfiles to see why that "status 101" message is being returned?

    Colin

  • tableFan22tableFan22 Posts: 8Questions: 2Answers: 0

    hello, I found my problem ..the problem was with the json reader

Sign In or Register to comment.