@@ -16,7 +16,7 @@ class Item(rx.Base):
1616
1717class 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 ):
0 commit comments