add search bar
This commit is contained in:
@@ -14,8 +14,10 @@ class ProductsPage:
|
||||
self.description = ft.TextField(label="Descriere", multiline=True, min_lines=3, max_lines=5)
|
||||
self.details = ft.TextField(label="Detalii", multiline=True, min_lines=3, max_lines=5)
|
||||
self.price = ft.TextField(label="Pret")
|
||||
self.discount = ft.TextField(label="Reducere (%)")
|
||||
self.discount = ft.TextField(label="Reducere (%)", value='0')
|
||||
self.quantity = ft.TextField(label="Cantitate")
|
||||
self.search_filed = ft.TextField(label="Cauta Produs", on_submit=self.on_search_btn_click, expand=True)
|
||||
self.search_btn = ft.IconButton(icon=ft.Icons.SEARCH, on_click=self.on_search_btn_click)
|
||||
self.product_image = ft.Image(
|
||||
width=150,
|
||||
height=150,
|
||||
@@ -31,6 +33,7 @@ class ProductsPage:
|
||||
],
|
||||
expand=True
|
||||
)
|
||||
self.aviability.value = 'in_stock'
|
||||
|
||||
self.category = ft.Dropdown(
|
||||
label="Categorie",
|
||||
@@ -110,6 +113,19 @@ class ProductsPage:
|
||||
]
|
||||
)
|
||||
|
||||
def on_search_btn_click(self, e):
|
||||
search = self.search_filed.value
|
||||
buffer = []
|
||||
for product in self._all_products:
|
||||
if search.lower() in product['name'].lower():
|
||||
buffer.append(product)
|
||||
self.products_list.controls.clear()
|
||||
self.search_filed.value = ''
|
||||
self.search_filed.update()
|
||||
self._all_products = self.product_manager.get_all()
|
||||
self.products_list.controls=self.create_list(buffer, self.edit_product, self.delete_product)
|
||||
self.products_list.update()
|
||||
|
||||
def on_file_picker_result(self, e: ft.FilePickerResultEvent):
|
||||
if e.files:
|
||||
file = e.files[0]
|
||||
@@ -299,6 +315,12 @@ class ProductsPage:
|
||||
],
|
||||
alignment=ft.MainAxisAlignment.SPACE_BETWEEN
|
||||
),
|
||||
ft.Row(
|
||||
[
|
||||
self.search_filed,
|
||||
self.search_btn,
|
||||
]
|
||||
),
|
||||
self.products_list
|
||||
],
|
||||
alignment=ft.MainAxisAlignment.START,
|
||||
|
||||
Reference in New Issue
Block a user