You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+61-2Lines changed: 61 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -171,6 +171,65 @@ That's it!
171
171
172
172
The library provides a few settings that you can define in the Django settings of your project:
173
173
174
-
-`DEFAULT_SORT_UP`, the HTML character to display the up symbol in the column headers (' ↑' by default).
175
-
-`DEFAULT_SORT_DOWN`, the HTML character to display the down symbol in the column headers (' ↓' by default).
174
+
### Sort indicators
175
+
176
+
By default, sort direction is shown using HTML entities (arrows):
177
+
178
+
-`DEFAULT_SORT_UP`, the HTML character to display the up symbol (' ↑' by default).
179
+
-`DEFAULT_SORT_DOWN`, the HTML character to display the down symbol (' ↓' by default).
180
+
181
+
Alternatively, you can use CSS classes for more flexible styling:
182
+
183
+
-`SORTING_CSS_CLASS_ASC`, CSSclass added to the anchor when sorted ascending (empty by default).
184
+
-`SORTING_CSS_CLASS_DESC`, CSSclass added to the anchor when sorted descending (empty by default).
185
+
186
+
Example withCSS classes:
187
+
188
+
```python
189
+
# settings.py
190
+
SORTING_CSS_CLASS_ASC = "sorted-asc"
191
+
SORTING_CSS_CLASS_DESC = "sorted-desc"
192
+
```
193
+
194
+
This will produce `<a class="sorted-asc"...>` when sorted ascending, allowing you to style the indicator withCSS:
195
+
196
+
```css
197
+
.sorted-asc::after { content: "\2191"; } /* Up arrow */
198
+
.sorted-desc::after { content: "\2193"; } /* Down arrow */
199
+
```
200
+
201
+
### Error handling
202
+
176
203
-`SORTING_INVALID_FIELD_RAISES_404`, if true, a 404 response will be returned on invalid use of query parameters (false by default).
204
+
205
+
## Default Sort Direction
206
+
207
+
By default, clicking a column header sorts ascending first. You can change this per-column to sort descending on first click (useful for date columns where you typically want most recent first):
The library uses Django ORM's `order_by()` for database fields, which is efficient. However, when sorting by model properties or computed attributes (not database fields), it falls back to Python sorting which loads all objects into memory.
222
+
223
+
For large querysets, ensure you're sorting by database fields only. You can check if a field will use Python sorting:
224
+
225
+
```python
226
+
from webstack_django_sorting.common import need_python_sorting
227
+
228
+
# Returns True if Python sorting will be used (slower)
229
+
need_python_sorting(queryset, "my_property")
230
+
```
231
+
232
+
If you must sort by a computed value on large datasets, consider:
233
+
- Adding a database field to store the computed value
0 commit comments