Skip to content

Commit 1bdda68

Browse files
committed
chore: bump version to 1.1.13b2 and update nested plugin for improved sorting with Subquery
1 parent ce1dd80 commit 1bdda68

3 files changed

Lines changed: 12 additions & 6 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "django-smartbase-admin"
3-
version = "1.1.13b1"
3+
version = "1.1.13b2"
44
description = ""
55
authors = ["SmartBase <info@smartbase.sk>"]
66
readme = "README.md"

src/django_smartbase_admin/plugins/nested.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646

4747
from django.contrib.postgres.aggregates import ArrayAgg
4848
from django.core.exceptions import FieldDoesNotExist, ImproperlyConfigured
49-
from django.db.models import Case, F, Max, Q, When
49+
from django.db.models import F, Q, OuterRef, Subquery
5050
from django.db.models.functions import Coalesce
5151

5252
from django_smartbase_admin.plugins.base import SBAdminPlugin
@@ -384,13 +384,18 @@ def _build_grouped_qs(
384384
# yields that parent's value — the group sorts by the
385385
# parent, not by any of its children.
386386
parent_row = Q(**{f"{parent_field}__isnull": True})
387+
column_fields_map = {cf.field: cf for cf in action.column_fields}
387388
sort_annotations: dict = {}
388389
new_order: list[str] = []
389390
for idx, expr in enumerate(order_strings):
390391
desc = expr.startswith("-")
391392
field = expr.lstrip("-+")
392393
alias = f"_nested_sort_{idx}"
393-
sort_annotations[alias] = Max(Case(When(parent_row, then=F(field))))
394+
visible_field = column_fields_map.get(field)
395+
sort_parent_qs = action.get_data_queryset(visible_fields=[visible_field] if visible_field else [])
396+
sort_annotations[alias] = Subquery(
397+
sort_parent_qs.filter(id=OuterRef("parent_real_id")).values(field)[:1]
398+
)
394399
new_order.append(f"-{alias}" if desc else alias)
395400
return grouped.annotate(**sort_annotations).order_by(*new_order)
396401

src/django_smartbase_admin/static/sb_admin/src/js/tabulator_layouts/fit_data_stretch_grow.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,21 @@ function fitDataStretchGrow(columns) {
4949
})
5050

5151
const targetCol = stretchCol || lastCol
52+
const naturalColWidth = targetCol ? targetCol.getWidth() : 0
5253

5354
if(targetCol) {
54-
gap = tableWidth - colsWidth + targetCol.getWidth()
55+
gap = tableWidth - colsWidth + naturalColWidth
5556

5657
if(this.table.options.responsiveLayout && this.table.modExists("responsiveLayout", true)) {
5758
targetCol.setWidth(0)
5859
this.table.modules.responsiveLayout.update()
5960
}
6061

61-
if(gap > 0) {
62+
if(gap > naturalColWidth) {
6263
targetCol.setWidth(gap)
6364
targetCol.modules.fitDataStretchGrowWidth = true
6465
} else {
65-
targetCol.reinitializeWidth()
66+
targetCol.setWidth(naturalColWidth)
6667
}
6768
} else if(this.table.options.responsiveLayout && this.table.modExists("responsiveLayout", true)) {
6869
this.table.modules.responsiveLayout.update()

0 commit comments

Comments
 (0)