Skip to content

Commit 1f6fca3

Browse files
committed
Fix dashboard template
1 parent 6ac16ea commit 1f6fca3

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

dashboard/dashboard/backend/table_state.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Item(rx.Base):
1616

1717
class TableState(rx.State):
1818
"""The state class."""
19-
19+
initial_entries: list[Item] = []
2020
items: List[Item] = []
2121

2222
search_value: str = ""
@@ -48,7 +48,9 @@ def filtered_sorted_items(self) -> List[Item]:
4848

4949
# Filter items based on search value
5050
if self.search_value:
51+
self.offset = 0 # Reset to the first page whenever a search is performed
5152
search_value = self.search_value.lower()
53+
5254
items = [
5355
item
5456
for item in items
@@ -62,6 +64,8 @@ def filtered_sorted_items(self) -> List[Item]:
6264
]
6365
)
6466
]
67+
else:
68+
items = self.initial_entries
6569

6670
return items
6771

@@ -71,8 +75,9 @@ def page_number(self) -> int:
7175

7276
@rx.var(cache=True)
7377
def total_pages(self) -> int:
74-
return (self.total_items // self.limit) + (
75-
1 if self.total_items % self.limit else 1
78+
total_filtered_items = len(self.filtered_sorted_items)
79+
return (total_filtered_items // self.limit) + (
80+
1 if total_filtered_items % self.limit else 1
7681
)
7782

7883
@rx.var(cache=True, initial_value=[])
@@ -99,6 +104,7 @@ def load_entries(self):
99104
with Path("items.csv").open(mode="r", encoding="utf-8") as file:
100105
reader = csv.DictReader(file)
101106
self.items = [Item(**row) for row in reader]
107+
self.initial_entries = self.items
102108
self.total_items = len(self.items)
103109

104110
def toggle_sort(self):

dashboard/dashboard/views/table.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def _pagination_view() -> rx.Component:
9595
align="center",
9696
width="100%",
9797
justify="end",
98-
),
98+
)
9999
)
100100

101101

0 commit comments

Comments
 (0)