0

I can't figure out how to solve this issue about sorting my table: table is rendered at this url: 127.0.0.1:8000/ip_teams/

but when I click on the name of the column to sort the table, url became: 127.0.0.1:8000/?sort=name it excludes the "ip_teams/" path.

This is my view:

class FoundationIPTypeList(SingleTableView):

    model = tracker_models.FoundationIPType
    table_class = tables.FoundationIPTypeTable

this is my table:

class FoundationIPTypeTable(django_tables.Table):
    class Meta:
        model = FoundationIPType
        attrs = {'class': "table table-striped table-condensed table-hover"}
        fields = ["name", "help_contact_email"]

this is my urls:

urlpatterns = [

#    url(r'^$', views.HomePageView.as_view(), name='home'), # Notice the URL has been named
    url(r'^about/$', views.AboutPageView.as_view(), name='about'),
    url(r'^ip_teams/$', views.FoundationIPTypeList.as_view(), name="ip_team_list"),

this is my template:

{% extends "base.html" %}
{% load render_table from django_tables2 %}


{% block pagecontent %}
<h1><center>Foundation IP Teams</center></h1>

<div class="container">
  <div class="panel panel-primary">
       {% render_table table %} 
  </div>
</div>

{% endblock %}

any ideas what is wrong? can't seem to find the answer anywhere. i thought this feature would work right out of the box.

table header row:

    <thead>
    <tr>


        <th class="name orderable"><a href="?sort=name&amp;name=unknown">Name</a></th>



        <th class="help_contact_email orderable"><a href="?sort=help_contact_email&amp;name=unknown">Help Contact Email</a></th>


    </tr>
</thead>
12
  • Did you try using the table filtering example in django-tables2.readthedocs.io/en/latest/pages/filtering.html? Try using that, and then add any customization you need for your project. Commented Nov 27, 2017 at 8:12
  • @Jieter i had started with django-tables2.readthedocs.io/en/latest/pages/… and then found a more generic way to do it, which is what i listed in my original comment. your comment refers to filtering, where i can't even get the basic stuff working like just having the resort of the columns work. the url created by django-tables2 is incorrect. Commented Nov 27, 2017 at 8:57
  • Yes, but you use custom code which I did not test/run. So that's why I suggest using something not custom to start with. If you do not want the filtering yet, use the example like you linked to and please update the code in your question accordingly. Commented Nov 27, 2017 at 9:07
  • @Jieter do i want to inherit from SingleTableMixin and FIlterView or just inherit from SingleTableView? i am confused as to what approach to take. i tried without any custom code using the simple example i gave and the same happened...no "ip_teams" in the url for sorting AND the filtering didn't work anymore. Commented Nov 28, 2017 at 3:14
  • First, try to inherit from SingleTableView. If that leads to working urls, try changing to inherit from (SingleTableMixin, FilterView) Commented Nov 28, 2017 at 6:34

1 Answer 1

2

Django-tables2 uses relative urls which add the sorting parameter. This works as long as the document does not contain a base tags, which change the base of any relative urls in the page.

Removing the <base> tag will fix your issue.

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

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.