3

I'm using Jquery Datatables. I am getting f is not defined console error. I am not using ajax request in Datatables.

Below is my Table:

<table id="myTable"  class="table table-striped table-bordered dataTable"  >

    <thead>
      <tr>
         <th>Trip ID</th>
         <th>User Name</th>
         <th>From</th> 
         <th>To</th>
     </tr>
    </thead>
    <tbody>
     <tr><td>123231</td></tr>
     <tr><td>John</td></tr>
     <tr><td>dfshggsf</td></tr>
     <tr><td>dsfgfsgfsg</td></tr> 
   </tbody>
    <tfoot>
         <tr>
          <th>Trip ID</th>
          <th>User Name</th>
          <th>From</th> 
          <th>To</th>       
         </tr>
    </tfoot> 
        </table>    
</table>

Below is the Jquery Code:

$(document).ready(function(){
      $('#myTable').DataTable({

          'ordering':false,
            dom: 'Bfrtip',

            buttons:[
                 {
                     extend: 'excelHtml5',
                     title: 'Data export'
                 },
                 {
                     extend: 'pdfHtml5',
                     title: 'Data export'
                 },
                  {
                     extend: 'csvHtml5',
                     title: 'Data export'
                 },
                  {
                     extend: 'print',
                     title: 'Data export'
                 } 
           ]
        });
    });

Below is the console error:

TypeError: f is undefined [Learn More] jquery.dataTables.min.js:27:64 jb http://localhost:8080/RajaRathaDashBoardApp/resources/js/jquery.dataTables.min.js:27:64 ga http://localhost:8080/RajaRathaDashBoardApp/resources/js/jquery.dataTables.min.js:48:224 e http://localhost:8080/RajaRathaDashBoardApp/resources/js/jquery.dataTables.min.js:92:256 m/< http://localhost:8080/RajaRathaDashBoardApp/resources/js/jquery.dataTables.min.js:92:342 each http://localhost:8080/RajaRathaDashBoardApp/resources/js/jquery-1.12.4.js:370:10 each http://localhost:8080/RajaRathaDashBoardApp/resources/js/jquery-1.12.4.js:137:10 m http://localhost:8080/RajaRathaDashBoardApp/resources/js/jquery.dataTables.min.js:82:457 h.fn.DataTable http://localhost:8080/RajaRathaDashBoardApp/resources/js/jquery.dataTables.min.js:164:289 http://localhost:8080/RajaRathaDashBoardApp/RajarathaTripHistory:38:4 fire http://localhost:8080/RajaRathaDashBoardApp/resources/js/jquery-1.12.4.js:3232:11 fireWith http://localhost:8080/RajaRathaDashBoardApp/resources/js/jquery-1.12.4.js:3362:7 ready http://localhost:8080/RajaRathaDashBoardApp/resources/js/jquery-1.12.4.js:3582:3 completed http://localhost:8080/RajaRathaDashBoardApp/resources/js/jquery-1.12.4.js:3617:3

Please help me solve this problem...Any help will be appreciated.

6
  • How are you importing the jQuery datatables library? Commented Dec 30, 2017 at 11:18
  • @yarwest using script tag, <script type="text/javascript" src="resources/js/jquery.dataTables.min.js"></script> Commented Dec 30, 2017 at 11:20
  • Can you provide the entire console error? Commented Dec 30, 2017 at 11:32
  • @yarwest TypeError: f is undefined [Learn More] jquery.dataTables.min.js:27:64 Commented Dec 30, 2017 at 11:35
  • Have you tried replacing the import of your local file with the online version? (cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js) Commented Dec 30, 2017 at 11:43

2 Answers 2

2

You have incorrect table structure in tbody section.

Corrected table structure is shown below.

<tbody>
   <tr>
      <td>123231</td>
      <td>John</td>
      <td>dfshggsf</td>
      <td>dsfgfsgfsg</td>
   </tr> 
</tbody>

See this example for code and demonstration.

Sign up to request clarification or add additional context in comments.

Comments

1

yup - that's how DataTables tells you that there is a mismatch in the table structure. The most likely solution is to make sure that your <th> row matches your <td> row.

I ran into this last night when I noticed that last_name wasn't part of the DataTables search box. DataTables searches against the field names provided in the column definition, not what is ultimately rendered out. So I added the last_name column as visible: false thinking it wouldn't need a header. Saw the same style error message and had to go back and add last to the header row = problem solved.

var columns = [

  { data: "first_name",
    render: function(data, type, row) {
      return row.first_name + " " + row.last_name;
    }
  },
  { data: "last_name",
    visible: false
  },
...
]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.