B4J Question B4XTable Reset Color after Search

MarcoRome

Expert
Licensed User
Longtime User
Hi All.
I'm using B4XTable.
I have the following problem the row is colored if a data is = 1.
Everything works.
But if i enter a search in the Search field, the line remains colored. How do I "reset" the colors just before the search and not after through the event ( DataUpdated)

1675581193586.png


After search

1675581213848.png


Thank you
UPDATE
In attachment file with solution
 

Attachments

  • ExampleB4XTable.zip
    34 KB · Views: 65
Last edited:

LucaMs

Expert
Licensed User
Longtime User
But if i enter a search in the Search field, the line remains colored. How do I "reset" the colors just before the search and not after through the event ( DataUpdated)
In the second image you posted, we see that you have carried out a new search, that row has remained highlighted and it is precisely in DataUpdated event that you have to manage it, not before carrying out the search.

If you wanted to do the latter, you would have to modify the B4XTable to add a TextChanged event to the search view (which is different depending on the "language", B4A, B4J, B4I).
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
In the second image you posted, we see that you have carried out a new search, that row has remained highlighted and it is precisely in DataUpdated event that you have to manage it, not before carrying out the search.

If you wanted to do the latter, you would have to modify the B4XTable to add a TextChanged event to the search view (which is different depending on the "language", B4A, B4J, B4I).

Thanks Luca for your answer.
I'll explain because i would like to avoid managing it in the DataUpdate event.
This event fires after searching.
In the grid, the row is highlighted in green under certain conditions.
When I search through SearchFilter, the same condition may occur. So it would be necessary to highlight the same.
I'll give you an example:
If you see in the first image there are 7 records. The 6th record is highlighted in green (it has the date 06/02/2023)
If you look at the second image, I searched via SerachFilter, so if I search by reporting the teacher's name, I would have expected the second row (it always has the date 06/02/2023) to be highlighted.
Instead it is not highlighted and always leaves the 6 line highlighted which it shouldn't.
Using the DataUpdate event that fires after the SeachFilter search, I can restore the colors, but I don't get the desired effect described above.
In essence, the SearchFilter does not restore the initial situation and does not report all the properties set while reading the DB such as highlighting the record.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I'm not sure I understood correctly (and unfortunately I don't have time right now).

Do you mean that initially you highlighted a row not based on a search but on a your condition (date 06/02/2023), then you want to search based, for example, on the teacher's name and you would like only those two rows (or with the same contents) were highlighted?

Even if that were the case, you'd have to write the source code that determines your condition anyway in that event routine. At least you can call the event routine directly.
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
I'm not sure I understood correctly (and unfortunately I don't have time right now).

Do you mean that initially you highlighted a row not based on a search but on a your condition (date 06/02/2023), then you want to search based, for example, on the teacher's name and you would like only those two rows (or with the same contents) were highlighted?

Even if that were the case, you'd have to write the source code that determines your condition anyway in that event routine. At least you can call the event routine directly.

We didn't understand each other. An example is attached.
As you can see "pippo" is highlighted in yellow.
If you now try to search by typing pippo, you will see that you will only get 2 records (right) but the 4th row, despite not having any data (it is empty) remains yellow, while the second record (the one showing the date 11/01/2023 ) should be yellow

 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
f you now try to search by typing pippo, you will see that you will only get 2 records (right) but the 4th row, despite not having any data (it is empty) remains yellow, while the second record (the one showing the date 11/01/2023 ) should be yellow
You need the code in this sub to erase the highlight of the blank rows:
B4X:
Sub B4XTable1_DataUpdated
    For i = 0 To B4XTable1.VisibleRowIds.Size - 1
        Dim RowId As Long = B4XTable1.VisibleRowIds.Get(i)
        If RowId > 0 Then
            Dim c As B4XTableColumn = B4XTable1.Columns.Get(2)  '3rd column
            Dim Value As String = B4XTable1.GetRow(RowId).Get(c.Id)
            If Value.Contains("11/01/2023") Then
                SetRowColor(i, xui.Color_Yellow)
                Continue
            End If
        End If
        'below lines are extremely important 
        If i Mod 2 = 0 Then
            SetRowColor(i, B4XTable1.EvenRowColor)
        Else
            SetRowColor(i, B4XTable1.OddRowColor)
        End If
    Next
End Sub
By the way, you never included your text files in your project
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
You have not sent the "example.csv" file.
If you want to send the project shown in that video...!
Sorry.
In the first thread I reinserted the correct file ( it contains both the csv file and the solution )
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
You need the code in this sub to erase the highlight of the blank rows:
B4X:
Sub B4XTable1_DataUpdated
    For i = 0 To B4XTable1.VisibleRowIds.Size - 1
        Dim RowId As Long = B4XTable1.VisibleRowIds.Get(i)
        If RowId > 0 Then
            Dim c As B4XTableColumn = B4XTable1.Columns.Get(2)  '3rd column
            Dim Value As String = B4XTable1.GetRow(RowId).Get(c.Id)
            If Value.Contains("11/01/2023") Then
                SetRowColor(i, xui.Color_Yellow)
                Continue
            End If
        End If
        'below lines are extremely important
        If i Mod 2 = 0 Then
            SetRowColor(i, B4XTable1.EvenRowColor)
        Else
            SetRowColor(i, B4XTable1.OddRowColor)
        End If
    Next
End Sub
By the way, you never included your text files in your project
Yes. This is solution.
You code work with out problem. Thank you @Mahares
Sorry.
In the first thread I reinserted the correct file ( it contains both the csv file and the solution )
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
You code work with out problem.
Glad it worked for you. If you want to even fine tune your project further, you can replace these 19 lines of code:
B4X:
Dim parser As CSVParser
    parser.Initialize
    Dim data As List = parser.Parse(File.ReadString(File.DirAssets, "example.csv"), ",", True)
    Dim data1 As List
    data1.Initialize
    For i = 0 To data.Size -1
        Dim val() As String = data.Get(i)
        Dim check_data As String = val(2)
        Dim row(3) As String
        row(0) = val(0)
        row(1) = val(1)
        row(2) = val(2)
        If check_data = "11/01/2023" Then
            SetRowColor(i, xui.Color_Yellow)
        End If
        data1.Add(row)
    Next
    Sleep(0)
    B4XTable1.SetData(data1)
With the below 4 lines and achieve the same result, unless your official big project is totally different:
B4X:
Dim parser As CSVParser
    parser.Initialize
    Dim data As List = parser.Parse(File.ReadString(File.DirAssets, "example.csv"), ",", True)
    B4XTable1.SetData(data)
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
Glad it worked for you. If you want to even fine tune your project further, you can replace these 19 lines of code:
B4X:
Dim parser As CSVParser
    parser.Initialize
    Dim data As List = parser.Parse(File.ReadString(File.DirAssets, "example.csv"), ",", True)
    Dim data1 As List
    data1.Initialize
    For i = 0 To data.Size -1
        Dim val() As String = data.Get(i)
        Dim check_data As String = val(2)
        Dim row(3) As String
        row(0) = val(0)
        row(1) = val(1)
        row(2) = val(2)
        If check_data = "11/01/2023" Then
            SetRowColor(i, xui.Color_Yellow)
        End If
        data1.Add(row)
    Next
    Sleep(0)
    B4XTable1.SetData(data1)
With the below 4 lines and achieve the same result, unless your official big project is totally different:
B4X:
Dim parser As CSVParser
    parser.Initialize
    Dim data As List = parser.Parse(File.ReadString(File.DirAssets, "example.csv"), ",", True)
    B4XTable1.SetData(data)
Thank you @Mahares
I know this.
The example was done this way because I initially thought that the DataUpdated event shouldn't be used (not knowing the same well) so I did it this way to color the record.
Now that i have studied this B4XTable i can better appreciate its power. Really great.
Thanks again for your support
 
Upvote 0
Top