Hi to all
I always continue with the same test project
I have inserted a label under the table that must indicate the number of records processed by the query
I followed your advice but I'm probably wrong
(see in the code '<<<<<)
Thanks
I always continue with the same test project
[BANanoVueMaterial] How to create dynamic data-table from database schema & data [SOLVED]
Hi the next step .....but always with the same problem of updating the component (VMDataTable) dt1 = VMDataTable in a module gestDatiArc is show and only the indication of the number of records in the pagination is updated but it does not show the name of the columns and records I read as you...
www.b4x.com
I followed your advice but I'm probably wrong
(see in the code '<<<<<)
B4X:
Sub Process_Globals
Public currentable As String
Public name As String = "gestdatiarc"
Private vm As BANanoVM
Private BANano As BANano 'ignore
Private vue As BANanoVue
Public lnamecol As List
Public ltypecol As List
Private dt1 As VMDataTable
Private lbcount As VMLabel '<<<<<
Private countrecord As Int '<<<<<
End Sub
B4X:
Public Sub Code
vm = pgIndex.vm
vue = vm.vue
Dim cont As VMContainer = vm.CreateContainer(name, Me)
'hide this container
cont.Hide
'
cont.AddRows(5).AddColumns12
'
dt1 = vm.CreateDataTable("dt1", "name", Me)
'dt1.SetTitle("?")
dt1.AddSearch
dt1.AddDivider
dt1.AddNew("btnNew", "mdi-plus", "Add a new record")
dt1.AddDivider
dt1.SetClearSort
dt1.SetItemsperpage("10")
dt1.SetPage("1")
dt1.SetMultiSort(True)
'NB: Add action buttons, these are based on templates and should be pre-defined
dt1.AddEditThrash
'dt1.AddDownload
'dt1.AddMenuV
'dt1.AddClone
'dt1.AddPrint
dt1.SetExternalPagination
dt1.SetCalculateWidths(True)
dt1.SetOnInput("dt1_input")
dt1.SetIconDimensions("edit", "32px", "success")
dt1.SetIconDimensions("delete", "32p", "error")
dt1.AddToContainer(cont, 1, 1)
'
lbcount = vm.CreateLabel("lblcount").SetText("{{ countrecord }}").SetSpan '<<<<< this lock the code
lbcount.SetH6
lbcount.AddToContainer(cont, 2,1)
'add container to page
vm.AddContainer(cont)
'register the sub routine
vm.SetMethod(Me, "LoadDatitb")
End Sub
B4X:
Sub LoadDatitb
'get the table name from the state
currentable = vm.getdata("currentable")
Log(currentable)
If currentable = "" Then Return
vm.PagePause
'vm.ShowLoading
'update the table title
lnamecol.Clear
ltypecol.Clear
Dim dbSchema As BANanoMySQLE
dbSchema.Initialize(pgIndex.db, "", "", "")
dbSchema.Execute($"DESCRIBE ${currentable.ToUpperCase}"$)
dbSchema.json = BANano.CallInlinePHPWait(dbSchema.MethodName, dbSchema.Build)
dbSchema.FromJSON
If dbSchema.OK = False Then
vm.ShowSnackBarError(dbSchema.error)
'vm.HideLoading
vm.PageResume
Return
End If
For Each fld As Map In dbSchema.Result
lnamecol.Add(fld.Get("Field"))
ltypecol.add(fld.Get("Type"))
Next
'define a new variable for records to avoid conflicts
Dim dbRecords As BANanoMySQLE
dbRecords.Initialize(pgIndex.db, "", "", "")
dbRecords.Execute($"SELECT * FROM ${currentable}"$)
dbRecords.json = BANano.CallInlinePHPWait(dbRecords.MethodName, dbRecords.Build)
dbRecords.FromJSON
'reset everything about the table
dt1.Reset
'add the new columns
For Each colName As String In lnamecol
dt1.AddColumn(colName, colName)
Next
'ensure the action buttons are visible
dt1.AddEditThrash
'dt1.AddDownload
'dt1.AddMenuV
'dt1.AddClone
'dt1.AddPrint
'build the new columns
dt1.ResetColumns
dt1.UpdateTitle(currentable.ToUpperCase)
'set the items of the table
dt1.SetDataSource(dbRecords.result)
vm.SetData("countrecord", dbRecords.result.size) '<<<<<
'
dt1.SetColumnWidth("id", 0) '<<<<< not work
'vm.HideLoading
vm.PageResume
End Sub
Thanks