Getting "Uncaught TypeError: Cannot read property 'type' of undefined" error message

Getting "Uncaught TypeError: Cannot read property 'type' of undefined" error message

pavpav Posts: 2Questions: 1Answers: 0

HTML

<table id="table_id">
       <thead>
           <tr>
               <th>Message</th>
               <th>Type</th>
               <th>Input</th>
               <th>File</th>
               <th>Line</th>
               <th>Notes</th>
               <th>Created at</th>
               <th></th>
           </tr>
       </thead>

   </table>

JavaScript

$(document).ready( function () {
   var table = $('#table_id').DataTable({
       "dom": 'R<"clear">lBfrtip',
       "lengthMenu": [10, 25, 50, 75, 100],
       "pageLength": 10,
       "serverSide": true,
       "processing": true,
       "ajax": {
       "url": "/admin/get/errors",
       "searching": true,
       
   },
   "columns": [
       {"data": "message"},
       {"data": "type"},
       {"data":"input"},
       {"data": "file"},
       {"data": "line"},
       {"data": "notes"},
       {"data": "created_at"},
       {defaultContent: '<button>delete</button>'}
   
   ],
   "columnDefs": [
       {"orderable": false, "targets": "_all"},
       {
           "searchable": false,
           "targets": [7]
       }
   ]
   
   });
   $('#table_id thead th').off('click')
   $('#table_id tbody').on('click', 'button', function(){
        var data = table.row($(this).parents('tr')).data();
        $.ajax({
            method: "POST",
            url: "post/delete",
            data: {id: data["id"]},
        });
        $("#table_id").DataTable().row($(this).parents('tr')).remove().draw();
   });

} );

I did this exact same thing for a similar table with much less entries and it worked perfectly fine. However, when I do this with my table with 147,270 entries, it throws me an error. It works with the first few pages, works when I just switch the pages with the "next" button. However, once I click on the last page or even the second last it starts throwing me that error. How do I fix it? Is there some sort of way to handle this error if the issue has to do with the amount of data it has to load?

Answers

  • kthorngrenkthorngren Posts: 21,327Questions: 26Answers: 4,949

    I would start by using the browser's network inspector to look at the data returned from the server when clicking on the last page button. Does it look correct?

    Can you post a link to your page or a test case replicating the issue so we can help debug?
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • pavpav Posts: 2Questions: 1Answers: 0

    I can not send a link to the page unfortunately. This works perfectly fine with the exact same method but with less entries. With more entries it works, it's just whenever I click on the last page sometimes it throws me that error.

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

    What is the JSON response from the server for the draw when that error happens please?

    Allan

Sign In or Register to comment.