ziovec Member Licensed User Oct 21, 2020 #1 Hello there, again Always experimentig around datatables and ingenous ways on how to populate them. I'm writing a web app in wich the user select some items from a table, it adds other parameters to it (such as quantity, package, customization etc.) and all the choosen items are safely stored in a txt file in this way: Code: Copy [AGRUMI MISTI VASO 18, 1, 6, null] [GERANIO PARIGINO V.27 COLONNA, 1, 6, null] [ROSA VASO 18 PIRAMIDE, 1, 6, null] [CICLAMINO MINI V. 11 PL., 1, 6, null] [GERANIO PARIGINO V.27 COLONNA, 1, 6, null] (this is just a test, forget about the null value). I would like to grab those lines and populare another datatable where the user could review their choices. Each line inside [ ] should be a row, and each column is separated by the comma. I was studying this function as a reference: Code: Copy Sub FillStudentsTable(jq As JQueryElement, rs As ResultSet) DateTime.DateFormat = "yyyy/MM/dd" 'sortable format Dim data As List data.Initialize Do While rs.NextRow Dim row As List row.Initialize For c = 0 To rs.ColumnCount - 1 Dim val As String = rs.GetString2(c) If c = 3 Then 'convert the birthday ticks value to a date string val = DateTime.Date(val) End If row.Add(val) Next data.Add(row) Loop rs.Close jq.RunMethod("dataTable", Array As Object(CreateMap("aaData": data, "bFilter": False, _ "bPaginate": True))) 'bind the selection changed event to the students table ws.RunFunction("addSelectionToTable", Array As Object(tblStudents.Id, "TableView1_SelectedRowChanged")) End Sub I know this works grabbing data from a ResultSet (wich is AWESOME!), but I can't find a way to work out how to proper store a list of arrays (wich is how the txt file is written). Any suggestion are kindly welcome ^^
Hello there, again Always experimentig around datatables and ingenous ways on how to populate them. I'm writing a web app in wich the user select some items from a table, it adds other parameters to it (such as quantity, package, customization etc.) and all the choosen items are safely stored in a txt file in this way: Code: Copy [AGRUMI MISTI VASO 18, 1, 6, null] [GERANIO PARIGINO V.27 COLONNA, 1, 6, null] [ROSA VASO 18 PIRAMIDE, 1, 6, null] [CICLAMINO MINI V. 11 PL., 1, 6, null] [GERANIO PARIGINO V.27 COLONNA, 1, 6, null] (this is just a test, forget about the null value). I would like to grab those lines and populare another datatable where the user could review their choices. Each line inside [ ] should be a row, and each column is separated by the comma. I was studying this function as a reference: Code: Copy Sub FillStudentsTable(jq As JQueryElement, rs As ResultSet) DateTime.DateFormat = "yyyy/MM/dd" 'sortable format Dim data As List data.Initialize Do While rs.NextRow Dim row As List row.Initialize For c = 0 To rs.ColumnCount - 1 Dim val As String = rs.GetString2(c) If c = 3 Then 'convert the birthday ticks value to a date string val = DateTime.Date(val) End If row.Add(val) Next data.Add(row) Loop rs.Close jq.RunMethod("dataTable", Array As Object(CreateMap("aaData": data, "bFilter": False, _ "bPaginate": True))) 'bind the selection changed event to the students table ws.RunFunction("addSelectionToTable", Array As Object(tblStudents.Id, "TableView1_SelectedRowChanged")) End Sub I know this works grabbing data from a ResultSet (wich is AWESOME!), but I can't find a way to work out how to proper store a list of arrays (wich is how the txt file is written). Any suggestion are kindly welcome ^^
Erel B4X founder Staff member Licensed User Longtime User Oct 21, 2020 #2 You need to create a List (data) where each item in this list (row) is a List by itself. It doesn't matter where the data come from. Upvote 0
You need to create a List (data) where each item in this list (row) is a List by itself. It doesn't matter where the data come from.
ziovec Member Licensed User Oct 21, 2020 #3 Erel said: You need to create a List (data) where each item in this list (row) is a List by itself. It doesn't matter where the data come from. Click to expand... B4X: Copy Dim ordine As List ordine.Initialize ordine.AddAll(Array As String(txtProduct.GetVal.Value, txtQta.GetVal.Value, selPack.GetVal.Value, selVarianti.GetVal.Value)) Dim ordine2 As List ordine2.Initialize ordine2.Add(ordine) TW.Initialize(File.OpenOutput(File.DirApp, "tmp_ordine.txt", True)) TW.WriteList(ordine2) TW.Close (TW is a Text Writer) This is how the txt file is written, it happens whenever the user click on a button to "add" the chosen product to the order. If I'm getting this right, ordine2 is a list of list (besides it gets re-initialized each time and so it contains one line at time, but I can avoid it)...can you confirm this? Upvote 0
Erel said: You need to create a List (data) where each item in this list (row) is a List by itself. It doesn't matter where the data come from. Click to expand... B4X: Copy Dim ordine As List ordine.Initialize ordine.AddAll(Array As String(txtProduct.GetVal.Value, txtQta.GetVal.Value, selPack.GetVal.Value, selVarianti.GetVal.Value)) Dim ordine2 As List ordine2.Initialize ordine2.Add(ordine) TW.Initialize(File.OpenOutput(File.DirApp, "tmp_ordine.txt", True)) TW.WriteList(ordine2) TW.Close (TW is a Text Writer) This is how the txt file is written, it happens whenever the user click on a button to "add" the chosen product to the order. If I'm getting this right, ordine2 is a list of list (besides it gets re-initialized each time and so it contains one line at time, but I can avoid it)...can you confirm this?
Erel B4X founder Staff member Licensed User Longtime User Oct 22, 2020 #4 ziovec said: This is how the txt file is written, Click to expand... Why not use File.WriteList? The code is mostly wrong. You are relying on the default string representation of List. This is a mistake. Use StringUtils.WriteCSV instead. Upvote 0
ziovec said: This is how the txt file is written, Click to expand... Why not use File.WriteList? The code is mostly wrong. You are relying on the default string representation of List. This is a mistake. Use StringUtils.WriteCSV instead.
ziovec Member Licensed User Oct 22, 2020 #5 Erel said: Why not use File.WriteList? Click to expand... Because this happen everytime the user clicks a button to select a product and add it to a cart. Usinge File.WriteList gets me a text file with only the very last item added, while I need to have ALL the products. With my code I obtain a text file composed this way, where each line is a list: B4X: Copy [AGRUMI MISTI VASO 18, 1, 6, null] [GERANIO PARIGINO V.27 COLONNA, 1, 6, null] [ROSA VASO 18 PIRAMIDE, 1, 6, null] [CICLAMINO MINI V. 11 PL., 1, 6, null] [GERANIO PARIGINO V.27 COLONNA, 1, 6, null] I NEED the text file to be like that, because I have to interact with another software that would read those lines and do stuff with them Also, instead of writing a list of list, if I would write just a list the output will be like this: B4X: Copy AGRUMI MISTI VASO 18 1 6 null GERANIO PARIGINO V.27 COLONNA 1 6 null ROSA VASO 18 PIRAMIDE 1 6 null CICLAMINO MINI V. 11 PL. 1 6 null GERANIO PARIGINO V.27 COLONNA 1 6 null Not very useful for my needs By the way, I managed to work out how to fill the table with a list ^^ Now I have other problems and shenaningans, but I'll open separated threads for them Upvote 0
Erel said: Why not use File.WriteList? Click to expand... Because this happen everytime the user clicks a button to select a product and add it to a cart. Usinge File.WriteList gets me a text file with only the very last item added, while I need to have ALL the products. With my code I obtain a text file composed this way, where each line is a list: B4X: Copy [AGRUMI MISTI VASO 18, 1, 6, null] [GERANIO PARIGINO V.27 COLONNA, 1, 6, null] [ROSA VASO 18 PIRAMIDE, 1, 6, null] [CICLAMINO MINI V. 11 PL., 1, 6, null] [GERANIO PARIGINO V.27 COLONNA, 1, 6, null] I NEED the text file to be like that, because I have to interact with another software that would read those lines and do stuff with them Also, instead of writing a list of list, if I would write just a list the output will be like this: B4X: Copy AGRUMI MISTI VASO 18 1 6 null GERANIO PARIGINO V.27 COLONNA 1 6 null ROSA VASO 18 PIRAMIDE 1 6 null CICLAMINO MINI V. 11 PL. 1 6 null GERANIO PARIGINO V.27 COLONNA 1 6 null Not very useful for my needs By the way, I managed to work out how to fill the table with a list ^^ Now I have other problems and shenaningans, but I'll open separated threads for them