How are you displaying you database table?
If you are using a kivymd data table, you would populate the column data and row data lists, pulling the data from your database.
After you update the row data, you would call update_row_data()
If you are using a RecycleView, the data is displayed as a list of dicts. You will pull the data from the db, and create the list of dicts. You would delete a row from the list of dicts, and the Recycle view will update when the property changes.
--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/268887625.199389.1628362884425%40mail.yahoo.com.
I’m not sure where you have having a problem.
I assume you are using a NavigationDrawer (is that correct?)
If so NavigationDrawer works with a screen manager and screens. Each screen has an even, on_pre_enter(), this event is fired when the screen is selected prior to the transition animation. You could use this event to populate you datatable. This would be appropriate if your data is changing frequently. If your data is not changing every time the screen is opened you could populate the data initially in App.on_start().
If you have some code, I’ll take a look.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/5b8d4d19-0e1f-40d2-90d6-c121ca24145bn%40googlegroups.com.
On Aug 7, 2021, at 5:04 PM, Elliot Garbus <elli...@cox.net> wrote:
You received this message because you are subscribed to a topic in the Google Groups "Kivy users support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/kivy-users/okBErmrebu4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/610ef56d.1c69fb81.c353b.6a31SMTPIN_ADDED_MISSING%40gmr-mx.google.com.
Here is an example of updating a datatable. See the comments…
from kivy.metrics import dp
from kivy.lang import Builder
from kivy.properties import ListProperty
from kivymd.app import MDApp
from kivymd.uix.datatables import MDDataTable
from random import randint
kv = """
BoxLayout:
orientation: 'vertical'
Button:
text:'Update Data'
size_hint_y: None
height: dp(48)
on_release: app.update_data()
"""
class Example(MDApp):
column_data = ListProperty()
row_data = ListProperty()
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.data_table = None # holds the data table instance
def build(self):
return Builder.load_string(kv)
def on_start(self):
# pull data from your database, and set the list propertie
# I am creating junk data here, you will pull the data from your db, and create tuples of the data to display
self.column_data = [ ("Column 1", dp(20)), ("Column 2", dp(30)), ("Column 3", dp(50))]
self.row_data = [(str(i), randint(10, 100), 'More Junk ' + str(randint(75, 150))) for i in range(10)]
self.data_table = MDDataTable(use_pagination=True, column_data=self.column_data, row_data=self.row_data)
self.root.add_widget(self.data_table)
def update_data(self):
# you would call this method with the on_pre_enter screen event
# load you data from the database, replace or extend the row_data list
self.row_data = [(str(i), randint(10, 100), 'Updated Data ' + str(randint(75, 150))) for i in range(5)]
self.data_table.update_row_data(self.data_table, self.row_data)
Example().run()
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/3bd5b550-9e12-4424-acea-cb9c415799fbn%40googlegroups.com.
There were a number of issues with the Layouts on the screen, such that you could not see the datatable. I quickly commented out the code and made a few other minor layout changes to the screen.
It is not pretty – but you can see the datatable.
''' id: data_layout
# ScrollView:
# do_scroll_x: False
# do_scroll_y: True
# effect_cls: ScrollEffect
#
# GridLayout:
# size_hint_y: None
# height: self.minimum_height
# cols: 1
# padding: "10dp"
# spacing: "10dp"
#
# MDLabel:
# text: 'Below is where a datatable would be of the rows from the database. id hour day month are the columns'
# text_size: self.width, None
# size_hint: 1, None
# height: self.texture_size[1]
#
# GridLayout:
# size_hint_y: None
# height: self.minimum_height
# cols: 1
# padding: "10dp"
# spacing: "10dp"
# AnchorLayout:
# id: data_layout
MDBoxLayout:
size_hint_y: None
height: dp(48)
MDTextField:
id: idtodelete
hint_text: "Enter Id To Delete"
helper_text: "id to delete"
helper_text_mode: "on_focus"
MDLabel:
id: statusmsg
text: ' '
text_size: self.width, None
# size_hint: 1, None
# height: self.texture_size[1]
MDRectangleFlatButton:
text: "Delete Id"
theme_text_color: "Custom"
text_color: 1, 0, 0, 1
line_color: 0, 0, 1, 1
# size_hint: (None, None)
on_release: app.delete_by_id()
# MDBoxLayout:
# # this is a placeholder The other objects are sized so this fills the remaining space
MDNavigationDrawer:
id: nav_drawer
ContentNavigationDrawer:
screen_manager: screen_manager
nav_drawer: nav_drawer
'''
class ContentNavigationDrawer(BoxLayout):
screen_manager = ObjectProperty()
nav_drawer = ObjectProperty()
class TestNavigationDrawer(MDApp):
def build(self):
return Builder.load_string(KV)
def load_data(self
):
self.data_tables = MDDataTable(size_hint=(1, 1),
column_data=[
("Not.", dp(30)),
("User", dp(30)),
("Password", dp(30)),
],
row_data=[
(
"1",
"The pitonist",
"Strong password",
),
(
"2",
"The c++ lover",
"Save me!!!:)",
),
])
self.root.ids.data_layout.add_widget(self.data_tables)
def delete_by_id(self):
# make sql connection
con = sql.connect('thedatabase.db')
f"delete from table1 where id = '{self.root.ids.idtodelete.text}')"
# print(tmpStr)
cur.execute(tmpStr)
con.commit()
con.close()
tmpStr = f'Updated Info'
self.root.ids.statusmsg.text = tmpStr
TestNavigationDrawer().run()
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/5485ae72-3b0d-418a-9342-141493a3c149n%40googlegroups.com.
Look at the simple example I sent.
In the App class in on_start() read the database, set the column and row data lists, and then instance the MDDataTable. In update_data(), you read you database and add or replace the data in the row data list. Call update date from the on_pre_enter event.
Notice in update data, the data_table method update_row_data(), this is used to update the table with new data.
In my example I created new data, self.data_row is a list, you can append or extend to add the data from your database.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/aac66c44-f036-42dd-94d9-3faf1c4afa04n%40googlegroups.com.
On Aug 8, 2021, at 5:03 PM, Elliot Garbus <elli...@cox.net> wrote:
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/6110468d.1c69fb81.f1f30.464dSMTPIN_ADDED_MISSING%40gmr-mx.google.com.
Glad you got it up and running!
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/32586BD5-6466-4E46-B412-0BFDAF028E1F%40gmail.com.