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

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

NubeProgrammerNubeProgrammer Posts: 1Questions: 1Answers: 0
edited March 2022 in Free community support

Hi guys,

I am trying to show a doctor's schedule on an HTML page. The data is coming from appointments already made. When printing the variable on the python script, everything is fine I can see the data but on the HTML page I keep on getting an uncaught type error.
Do you see anything wrong with the below?

This is my script:

    var table = $(document).ready(function() {
  $('#schedule').DataTable({


    "ajax": '/api/schedule',
    columns: [{
        schedule: 'first_name'
      },
      {
        schedule: 'second_name'
      },
      {
        schedule: 'date',
        searchable: true
      },
      {
        schedule: 'slot_time',
        searchable: true
      },
      {
        schedule: 'Description'
      }
    ],
  });
});

This is my HTML:

table id="schedule" class="table table-stripped" style="width:100%">
  <thead>
    <tr>
      <th>First Name</th>
      <th>Second Name</th>
      <th>Date</th>
      <th>Slot Time</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
  </tbody>
</table>

Answers

  • kthorngrenkthorngren Posts: 20,313Questions: 26Answers: 4,771
    edited March 2022

    Looks like what you want to use is columns.data. Instead of this:

          {
            schedule: 'second_name'
          },
    

    Use:

          {
            data: 'second_name'
          },
    

    Depending on your data structure this may or ma not work. The schedule would be a columns option definition, which Datatables doesn't know about. See the Data and Ajax docs for more information about Datatables supported data structures.

    Kevin

Sign In or Register to comment.