Josema_23
Josema_23

Reputation: 306

Javascript tablesorter plugin does not work

I'm trying to include the tablesorter plugin in my code, but it doesn't work. I have added the jquery library and the tablesorter file, but it doesn't do anything. Here's my code:

Scripts added:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script type="text/javascript" src="{% static 'MIDIPIRCUSSION_APP/jquery.tablesorter.js' %}"></script>

HTML code:

    <div class="jumbotron2">
            <div class="container">
            <br>
        <center>
        <table id="myTable" class="table table-dark"  style="text-align: center">
            <thead>
                <tr>
                    <th>Fecha de Creación</th>
                    <th>Título</th>
                    <th>Duracion</th>
                    <th>Dificultad</th>

                    {% if not user.is_staff %}

                        <th>Jugar</th>

                    {% endif %}

                    <th>Configurar Bateria</th>


                    {% if user.is_staff %}
                        <th>Modificar</th>
                        <th>Eliminar</th>
                    {% endif %}

            </thead>

            {% for cancion in object_list %}
            <tbody>
                <tr>
                    <td>{{cancion.creacion}}</td>
                    <td>{{cancion.titulo}}</td>
                    <td>{{cancion.duracion}}</td>
                    <td>{{cancion.dificultad}}</td>
</tbody>
</table>

javascript code:

<script>
$(document).ready(function() { 
  $("myTable").tablesorter(); 
    });
</script>

Upvotes: 1

Views: 33

Answers (2)

Josema_23
Josema_23

Reputation: 306

I found the error. I was using two different ways to load jquery, with different versions, so I was not using the correct one.

Upvotes: 0

charlietfl
charlietfl

Reputation: 171679

Selector is invalid ... it should be $("#myTable")

$("myTable") is looking for a tag <myTable></myTable> that doesn't exist

Upvotes: 1

Related Questions