Hi there
THIS PROJECT IS NO LONGER BEING MAINTAINED, A BETTER ALTERNATIVE EXISTS, SEARCH FOR B4XTABLE
MashPropertyBag Download
This is a series in an article of the MashPropertyBag...
02 April 2018 Update...
Just added functionality to export the contents to Excel using JPOI. It is as simple as..
Example based on the b4xgoodies MashOverViewCreator. listings
15 March 2018 Update
Download Location
The control has now been linked to an SQLite backend as demonstrated in this video below.
I will adding paging facility some time later... This has been simply been created with these few lines of code.
Old Stuff
Well, I have been planning to do this for a while now and the 'need' for it came crashing down me once more.
Why?
1. I just wanted to use normal controls like textboxes, comboboxes, checkboxes etc.
2. I also needed to get the saved/updated/deleted record as a map, remove it from the tableview etc easy peasy.
3. Flexibility of being able to do anything with it.
I first asked a question about this sometime ago and then left it there.. and developing my own propertybag here taught me a lot as a result this just extends that for row functionality.
This is just so exciting..
See the "Log" during the operation of my video example here, the records are returned as Maps that you can manipulate.
Reproduction:
Create a view in the designer and drop the CustomView : EditableLV
In class globals, define your EditableLV
Then, add columns to the tableview that you will be processing, these indicate the type of column, the width, etc
Extra methods...
From the example, I have a button to add new records to the TableView, this calls...
The tableview columns have been defined above with default values, so the AddRowEmpty methods takes from that and creates an empty row for you. Remember the id is specified as -1 default value, so automatically assumes a new record mode.
Clicking the Save image for a records calls this method...
and the delete call for each record...
You can then manipulate the records as you please.
In summary
1. Load records from a datasource
2. Create new records and save them
3. Delete records
Magic!
PS: I will upload the source code asap so that you can customize to your needs e.g. theme etc.
THIS PROJECT IS NO LONGER BEING MAINTAINED, A BETTER ALTERNATIVE EXISTS, SEARCH FOR B4XTABLE
MashPropertyBag Download
This is a series in an article of the MashPropertyBag...
02 April 2018 Update...
Just added functionality to export the contents to Excel using JPOI. It is as simple as..
B4X:
'set report options
Dim opt As ReportHeading = MashPOI.PoiSetHeading(True,fx.Colors.Yellow,"Arial",16,True)
Dim rh As ReportHeading = MashPOI.PoiSetHeading(True,fx.Colors.Red,"Arial",10,False)
'MashPOI.PoiExportList(File.DirApp,filePath,"",filePath,filePath,headings,opt,rh,True,rows)
tbl.Export2Excel(File.DirApp,filePath,"",filePath,filePath,opt,rh,True)
Example based on the b4xgoodies MashOverViewCreator. listings
15 March 2018 Update
Download Location
The control has now been linked to an SQLite backend as demonstrated in this video below.
I will adding paging facility some time later... This has been simply been created with these few lines of code.
B4X:
#Region Project Attributes
#MainFormWidth: 1500
#MainFormHeight: 700
#End Region
Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Private btnNewRecord As Button
Private lstRecords As EditableTV
Private btnDeleteAll As Button
Private btnSaveAll As Button
Private dbFile As String
Private cSQL As SQL
Private dbPath As String
End Sub
#AdditionalJar: MashPropertyBagRes
#AdditionalJar: sqlite-jdbc-3.7.2
Sub PrepareDB
If File.Exists(File.DirApp,"contacts.db") = False Then
File.Copy(File.DirAssets,"contacts.db",File.DirApp,"contacts.db")
End If
cSQL.InitializeSQLite(File.DirApp,"contacts.db",False)
dbPath = File.Combine(File.DirApp,"contacts.db")
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.RootPane.LoadLayout("vTableEdit") 'Load the layout file.
MainForm.Title = "My Contacts"
PrepareDB
'setup the table fields
lstRecords.SetParentForm(MainForm)
lstRecords.loadcss
lstRecords.SetReportViewer
'indicate required fieldsd
lstRecords.ResetRequired
lstRecords.AddRequired("firstname").AddRequired("lastname")
'start: set database link IMPORTANT
lstRecords.PrimaryKey = "id"
lstRecords.SecondaryKey = "firstname"
lstRecords.DataSource = "contacts"
lstRecords.DataBase = dbPath
lstRecords.HandleCrud = True
'end : set database link
lstRecords.AddLabel("id",30,"#","-1") 'IMPORTANT
lstRecords.AddTextBox("firstname",200,"First Name","")
lstRecords.AddTextBox("lastname",200,"Last Name","")
lstRecords.AddComboBox("gender",100,"Gender",lstRecords.CreateList(",","Male,Female"),"Male")
lstRecords.AddDatePicker("dob",200,"Date of Birth","2017-01-01")
lstRecords.AddCheckBox("active",100,"Active","True")
lstRecords.ShowUpdate = True
lstRecords.ShowDelete = True
lstRecords.ShowClone = True
lstRecords.TabIndex = ""
lstRecords.AlwaysTell = True
lstRecords.RefreshColumns
MainForm.Show
lstRecords.SQLQuery = "select * from contacts order by firstname,lastname"
lstRecords.LoadSQLData(Null)
End Sub
'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
Return True
End Sub
'add an empty row to the table using default values
Sub btnNewRecord_Click
lstRecords.AddRowEmpty
End Sub
'a record has been saved/updated, get row and its map
Sub lstRecords_Update(RowIndex As Int,Value As Map)
Log("Update: " & Value)
End Sub
'a record has been deleted, get row and its map
Sub lstRecords_Delete(RowIndex As Int, Value As Map)
Log("Delete: " & Value)
End Sub
'save all records
Sub btnSaveAll_Click
lstRecords.save
End Sub
'delete all records
Sub btnDeleteAll_Click
lstRecords.Delete
End Sub
Sub etvRecords_Clone (RowIndex As Int, Value As Map)
'get the old id
Dim oldid As String = Value.getdefault("oldid9999","")
'get the new id
Dim id As String = Value.GetDefault("id","")
'remove oldid
End Sub
Old Stuff
Well, I have been planning to do this for a while now and the 'need' for it came crashing down me once more.
Why?
1. I just wanted to use normal controls like textboxes, comboboxes, checkboxes etc.
2. I also needed to get the saved/updated/deleted record as a map, remove it from the tableview etc easy peasy.
3. Flexibility of being able to do anything with it.
I first asked a question about this sometime ago and then left it there.. and developing my own propertybag here taught me a lot as a result this just extends that for row functionality.
This is just so exciting..
See the "Log" during the operation of my video example here, the records are returned as Maps that you can manipulate.
Reproduction:
Create a view in the designer and drop the CustomView : EditableLV
In class globals, define your EditableLV
B4X:
Private lstRecords As EditableTV
Then, add columns to the tableview that you will be processing, these indicate the type of column, the width, etc
B4X:
'setup the table fields
lstRecords.SetParentForm(frm,True)
lstRecords.SetReportViewer
lstRecords.PrimaryKey = "id" 'important
lstRecords.AddLabel("id",30,"#","-1") 'IMPORTANT
lstRecords.AddTextBox("firstname",200,"First Name","")
lstRecords.AddTextBox("lastname",200,"Last Name","")
lstRecords.AddComboBox("gender",100,"Gender",jMash.CreateList(",","Male,Female"),"Male")
lstRecords.AddDatePicker("dob",200,"Date of Birth","2017-01-01")
'lstRecords.AddColorPicker("eyecolor",200,"Eye Color","")
lstRecords.AddCheckBox("active",100,"Active","True")
lstRecords.RefreshColumns
'Load some example records to the tableview
LoadRecords
Extra methods...
B4X:
Sub LoadRecords()
'lstRecords.AddRecords(lst) passing it a list of records from a db example from ExecuteMaps
lstRecords.AddRowM(-1,CreateMap("id":1,"firstname":"Mashy","lastname":"Mbanga","dob":"1973-04-15","gender":"Male","active":"False","skill":"Programming"))
lstRecords.AddRowM(-1,CreateMap("id":2,"firstname":"Ozzie","lastname":"Mbanga","dob":"2010-04-15","gender":"Male","active":"True","skill":"Programming"))
lstRecords.AddRowM(-1,CreateMap("id":3,"firstname":"Orio","lastname":"Mbanga","dob":"2010-04-15","gender":"Female","active":"True","skill":"Programming"))
lstRecords.AddRowM(-1,CreateMap("id":4,"firstname":"Ernesto","lastname":"Mbanga","dob":"2009-04-15","gender":"Female","active":"True","skill":"Programming"))
'use recTot as a ficticious primary key
recTot = lstRecords.recordcount
End Sub
From the example, I have a button to add new records to the TableView, this calls...
B4X:
'add an empty row to the table using default values
Sub btnNewRecord_Click
lstRecords.AddRowEmpty
End Sub
The tableview columns have been defined above with default values, so the AddRowEmpty methods takes from that and creates an empty row for you. Remember the id is specified as -1 default value, so automatically assumes a new record mode.
Clicking the Save image for a records calls this method...
B4X:
'a record has been saved/updated, get row and its map
Sub lstRecords_Update(RowIndex As Int,Value As Map)
Log("save action")
Dim json As String = lstRecords.Map2Json(Value)
Log(json)
'if this was a new recors, update its primary key, you can get the primary key from a db and use that here.
Dim lastID As Int = Value.Getdefault("id",-1)
If lastID = -1 Then
recTot = recTot + 1
Value.Put("id",recTot)
End If
'update the id of the table
lstRecords.UpdateRow(RowIndex,Value)
End Sub
and the delete call for each record...
B4X:
'a record has been deleted, get row and its map
Sub lstRecords_Delete(RowIndex As Int, Value As Map)
Dim resp As String = jMash.MsgBoxConfirm(frm,"Confirm Delete","Are you sure that you want to delete this record?")
If resp = "no" Then Return
'user wants to delete the record, do it
lstRecords.RemoveRow(RowIndex)
Log("delete action")
Dim json As String = lstRecords.Map2Json(Value)
Log(json)
End Sub
You can then manipulate the records as you please.
In summary
1. Load records from a datasource
2. Create new records and save them
3. Delete records
Magic!
PS: I will upload the source code asap so that you can customize to your needs e.g. theme etc.
Last edited: