1

I know I should put up some code with what I've tried but I don't know where to start.

In Django admin I can display data so that it can be sorted by the user using:

class MyModelAdmin(admin.ModelAdmin):
    list_display = ['field1', 'field2']
    ordering = ['field2','field1']

Within the admin site, users will be able to click the top of the column and reorder on that column.

I want to replicate this functionality in an non-admin screen. How do I do that?

HenryM
  • 5,557
  • 7
  • 49
  • 105

1 Answers1

0

You have two approaches available:

  1. Import and modify the admin templates to use their sortable functionality. This answer covers the basics very well., but the ModelAdmin class has a lot of functionality, which you may or may not actually need. You can start from the admin templates more generally if you want to go down that route.
  2. Use an external library to manage in the templates.

I find the latter approach is actually easier, faster and more easily extensible. I have just implemented this in a project using datatables, which takes a couple of minutes, assuming you already have a table.

Community
  • 1
  • 1
Withnail
  • 3,128
  • 2
  • 30
  • 47