en Lopes
en Lopes

Reputation: 2153

DataTable Sorting - Sorting by a click on the header

I have created this datatable:

<script type="text/javascript">
  $(document).ready(function() {
    const table1 = $('#songs').DataTable({
      searching: false,
      paging: false
    });
  });
</script>

but when I click on the header nothing happens

http://45.79.248.19:8080/songs

Upvotes: 1

Views: 1882

Answers (1)

Cuong Le Ngoc
Cuong Le Ngoc

Reputation: 11975

From your code:

<tbody>
  <tr>
    <th>BPM</th>
    <th>ARTIST</th>
    <th>ALBUM</th>
    <th>LABEL</th>
    <th>SONG</th>
  </tr>
  ...

You are putting your th inside tbody. That's the problem. You need to put your th in thead tag because it allows DataTables to know what should be used for the column headers and the click-to-order controls.

Fiddle

More info here.

Upvotes: 1

Related Questions