Skip to content

Commit 24767d2

Browse files
entorbfalkoschindlerclaude
authored
Update trello_cards: add drag and drop support for reordering in same column (#5934)
### Motivation trello_cards: add drag and drop support for reordering in same column ### Implementation - minor improvement of the example - applied ruff code formatting ### Progress - [x] The PR title is a short phrase starting with a verb like "Add ...", "Fix ...", "Update ...", "Remove ...", etc. - [x] The implementation is complete. (Otherwise, open a [draft PR](https://github.blog/news-insights/product-news/introducing-draft-pull-requests/).) - [x] This PR does not address a security issue. (Security fixes must be coordinated via the [security advisory](https://github.com/zauberzeug/nicegui/security/advisories/new) process before opening a PR.) - [x] Pytests are not necessary. - [x] Documentation is not necessary. - [x] No breaking changes to the public API --------- Co-authored-by: Falko Schindler <falko@zauberzeug.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 11bd43b commit 24767d2

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

examples/trello_cards/draganddrop.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class Item(Protocol):
1111

1212

1313
dragged: card | None = None
14+
target: card | None = None
1415

1516

1617
class column(ui.column):
@@ -32,13 +33,14 @@ def unhighlight(self) -> None:
3233
self.classes(remove='bg-blue-grey-3', add='bg-blue-grey-2')
3334

3435
def move_card(self) -> None:
35-
global dragged # pylint: disable=global-statement # noqa: PLW0603
36+
global dragged, target # pylint: disable=global-statement # noqa: PLW0603
37+
assert dragged is not None
3638
self.unhighlight()
37-
dragged.parent_slot.parent.remove(dragged)
38-
with self:
39-
card(dragged.item)
40-
self.on_drop(dragged.item, self.name)
39+
dragged.move(self, self.default_slot.children.index(target) if target and target in self else -1)
40+
if self.on_drop:
41+
self.on_drop(dragged.item, self.name)
4142
dragged = None
43+
target = None
4244

4345

4446
class card(ui.card):
@@ -49,7 +51,12 @@ def __init__(self, item: Item) -> None:
4951
with self.props('draggable').classes('w-full cursor-pointer bg-grey-1'):
5052
ui.label(item.title)
5153
self.on('dragstart', self.handle_dragstart)
54+
self.on('dragover.prevent', self.handle_dragover)
5255

5356
def handle_dragstart(self) -> None:
5457
global dragged # pylint: disable=global-statement # noqa: PLW0603
5558
dragged = self
59+
60+
def handle_dragover(self) -> None:
61+
global target # pylint: disable=global-statement # noqa: PLW0603
62+
target = self

0 commit comments

Comments
 (0)