B4J Question [BANanoVuetifyAD3] Data Binding v-caledar <-> mysql

Mashiane

Expert
Licensed User
Longtime User
The v-calendar does not work like the v-data-table that you can easily "bind", you need to add each entry to it when you read from the db, via a loop.

This app here uses the same approach: https://www.b4x.com/android/forum/t...-bvad3-source-code-for-sale-8.129001/#content

1st Option

1. Create a database with the events schema that you want to use to store events (see the definition below for adding an event to the calendar)

2. After loading the calendar on a page, i.e on the "oncreate" sub, call

B4X:
calendar.Clear(component)

To clear any entries that are on the calendar.

3. Then loop through all the items from your table and add each one with calendar.additem.

B4X:
Sub AddItem(eID As String, eCategory As String, eName As String, eStart As String, eEnd As String, eColor As String, eAllDay As Boolean, eLocation As String, eNote As String)

4. Call Refresh
B4X:
Sub Refresh(C As VueComponent)

This will get all the events you added from the "temporal" store and update the calendar UI.

2nd option

Create an events table with these "exact matching" field names ie. lowercase as per AddItem Subroutine above

B4X:
Sub AddItem(eID As String, eCategory As String, eName As String, eStart As String, eEnd As String, eColor As String, eAllDay As Boolean, eLocation As String, eNote As String)
    Dim ne As Map = CreateMap()
    ne.Put("id", eID)
    ne.Put("name", eName)
    ne.Put("start", eStart)
    ne.Put("end", eEnd)
    ne.Put("color", eColor)
    ne.Put("timed", eAllDay)
    ne.Put("category", eCategory)
    ne.Put("note", eNote)
    ne.Put("location", eLocation)
    mEvents.Add(ne)
End Sub

Then after you get the list of events from the database, execute

B4X:
calendar.UpdateEvents(component, itemsFromDB)
 
Upvote 0
Top