{% load coffee_table pagination_tags resort %}

{% auto_sort object_list %}
{% if paginate_by %}
    {% autopaginate object_list paginate_by %}
{% else %}
    {% autopaginate object_list 50 %}
{% endif %}

<div class="table-collapse" style="overflow:auto">
    <table class="{% if table_class %}{{ table_class }}{% else %}table{% endif %}">
        {% for object in object_list %}
            {% if forloop.first %}
                <thead>
                    <tr>
                        {% if checkbox_column %}
                            <th class="select"><input type="checkbox"></th>
                        {% endif %}

                        {% for field_accessor, field in fields %}
                            {% if primary_key_column %}
                                <th>
                                    {% sort_link field.verbose_name|title field.name %}
                                    <sup>
                                        {% if help_text %}{% if not field.help_text == '' %}
                                            <a href="#" data-toggle="tooltip" title="{{ field.help_text }}">?</a>
                                        {% endif %}{% endif %}
                                    </sup>
                                </th>
                            {% else %}
                                {% ifnotequal field|get_field_type 'AutoField'  %}
                                    <th>
                                        {% sort_link field.verbose_name|title field.name %}
                                        <sup>
                                            {% if help_text %}{% if not field.help_text == '' %}
                                                <a href="#" data-toggle="tooltip" title="{{ field.help_text }}">?</a>
                                            {% endif %}{% endif %}
                                        </sup>
                                    </th>
                                {% endifnotequal %}
                            {% endif %}
                        {% endfor %}
                        {% include 'coffee_table/extra_headers.html' %}
                    </tr>
                </thead>
                <tbody>
            {% endif %}
            <tr>
                {% if checkbox_column %}
                    <td><input type="checkbox" name="action-select" value="{{ object.pk }}"></td>
                {% endif %}
                {% for field_accessor, field in fields %}
                    {% if primary_key_column %}
                        <td>{% include 'coffee_table/field.html' %}</td>
                    {% else %}
                        {% ifnotequal field|get_field_type 'AutoField'  %}
                            <td>{% include 'coffee_table/field.html' %}</td>
                        {% endifnotequal %}
                    {% endif %}
                {% endfor %}
                {% include 'coffee_table/extra_columns.html' %}
            </tr>
        {% endfor %}
        </tbody>
    </table>
</div>
{% paginate %}