|
| 1 | +--- |
| 2 | +sidebar_position: 5 |
| 3 | +--- |
| 4 | +import Tabs from '@theme/Tabs'; |
| 5 | +import TabItem from '@theme/TabItem'; |
| 6 | + |
| 7 | +# Reordering List View |
| 8 | + |
| 9 | +You can enable **manual reordering** of items within the SBAdmin list view using the `sbadmin_list_reorder_field`. This allows admins to define the visible order of items using drag-and-drop, even when pagination is enabled. |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | +### Prerequisites |
| 14 | + |
| 15 | +To enable reordering: |
| 16 | + |
| 17 | +1. Your model must include a field (e.g. `order_by`) to track order. |
| 18 | +2. You must configure both `sbadmin_list_reorder_field` and `ordering`. |
| 19 | + |
| 20 | +### 💡Example |
| 21 | + |
| 22 | +```python title="catalog/sb_admin.py" |
| 23 | +@admin.register(ReorderModel, site=sb_admin_site) |
| 24 | +class ReorderModelSBAdmin(SBAdmin): |
| 25 | + model = ReorderModel |
| 26 | + |
| 27 | + # Enables reordering via drag-and-drop |
| 28 | + sbadmin_list_reorder_field = "order_by" |
| 29 | + ordering = ["order_by"] |
| 30 | + |
| 31 | + # Basic list view config |
| 32 | + sbadmin_list_display = ["name"] |
| 33 | + search_fields = ["name"] |
| 34 | + |
| 35 | + fieldsets = [ |
| 36 | + (None, {"fields": ["name"]}), |
| 37 | + ] |
| 38 | +``` |
| 39 | + |
| 40 | +Once enabled, a Reorder button will appear in the list view toolbar. |
| 41 | + |
| 42 | + |
| 43 | +Clicking it will redirect to a special Reorder View, where you can: |
| 44 | +Drag and drop rows to change order. |
| 45 | + |
| 46 | +:::warning[Keep in mind] |
| 47 | +If you are testing this functionality in [Demo project](https://sbadmin.sbdev.sk/), database works in read-only mode. Reorder will not save. |
| 48 | +::: |
0 commit comments