B4J Question B4XTable Search using another search field

Pelky

Active Member
Licensed User
Longtime User
Hello all you Clever people out there

I was wondering if it was possible to hide the search in the B4Xtable and use a field from a screen capture form?
What I am trying to do is show a form and as the user captures the data a pop up starts to show matching entries
 

Pelky

Active Member
Licensed User
Longtime User
So what you actually want has nothing to do with the "database" view with a B4XTable. So what you want is to extract information from a webpage and use it.































































Not at I perhaps should have been clearer all...































































































































































































































































































































































































































































The code snipped [B4J] send string msg from WebView js 2 B4J - and from B4J to WebView javascript is a good starting point.
 
Upvote 0

Pelky

Active Member
Licensed User
Longtime User
Firstly I would like to thank you for your response.

Sadly that is not what I was looking for. Perhaps I wasn't clear. B4XTABLE has a search field which can be hidden. This search field is used to search a database and show it in Table format. This search field is shown by default.

What I want to do is hide this 'default' search field and use another field to search the database with. This 'other' search field could be part of a form.
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
....hmmm....

Do you want something like this?

following example... I love this way of searching my tables of dbs... actually i was thinking put that code as snippet - for helping other users create a better search for their databases... Search with LIKE and "AND" is favour for all !

Add a view to layout: searchtextfield (b4xfloattextfield) - Generate member..., also if you want it more analytic add a button (name it btnsearch ...swiftbutton) too..

B4X:
'add those at class_globals:

    Dim SQLsearch As String = ""
    Dim SQLtable As String ' the table you will show/search...
    Dim SQLargs As List 'the args can be the all the columns as you can see in this example... auto-creating....
    Dim sql1 As String   ' here can be the column/fields of table you wanna show for example: id, customername, telephone, email

Private Sub searchtext_EnterPressed
    searchtext.TextField.SelectAll
    btnsearch_Click
End Sub

Private Sub btnsearch_Click
    If searchtext.Text.ToLowerCase.Trim.Length>0 Then
        Dim searchtocolumns() As String = Regex.Split(" ",searchtext.Text.ToUpperCase)  '...i like uppercase all letters... i am doing that when writting to db too... especially at sqlite databases... because of limitations they have...
        Dim newargs As String
        Dim sb2 As StringBuilder
        sb2.Initialize

        SQLargs.Clear
        Dim rs As ResultSet = datadb.ExecQuery("SELECT " & sql1 & " FROM " & SQLtable & " LIMIT 1")
        For I = 0 To searchtocolumns.Length-1
            sb2.Append("(")
            For K = 0 To rs.ColumnCount-1
                sb2.append("upper(").Append(rs.GetColumnName(K)).Append(")").Append(" LIKE ?")
                SQLargs.Add("%" & searchtocolumns(I).ToUpperCase & "%")
                If K<rs.ColumnCount-1 Then
                    sb2.Append(" OR ")
                End If
            Next
            sb2.Append(")")
            If I<searchtocolumns.Length-1 Then
                sb2.Append(" AND ")
            End If
        Next
        newargs=sb2.ToString
        rs.CLOSE

        B4XTable1.BuildQuery(False)
        SQLsearch="SELECT " & sql1 & " FROM "& SQLtable & " WHERE " & newargs
        LoadData  'a sub that you will load all values of database you want to a b4xtable - there are many examples.... using sqlsearch... ofcourse there are many other ways....

 
    Else
'        ...here you can show all your records...
    End If

End Sub

How it works in runtime... when user writing for example two words: JAMES HOTMAIL --> this will show all rows have fields containing JAMES and HOTMAIL.. you can change to OR by placing a swith or selecting or by default... if the user give 3 words or 4 words... will automatically create different sqlargs...

Hope it helps... ofcourse before use this example you must search and know how to show an sqlite (or mysql, ms sql table) to b4xtable...

ps: datadb is an SQL... sqlite/mssql/mysql already loaded/initialized...
 
Last edited:
Upvote 0

Mahares

Expert
Licensed User
Longtime User
What I want to do is hide this 'default' search field and use another field to search the database with. This 'other' search field could be part of a form.
Here is my take on this if you like simple things. If the search string from your form is pasted in an edit text, you can create a DataView and do not have to worry or deal with the SearchField completely.
B4X:
Sub Button2_Click    
    If Button2.Text="Filter" Then  'button text
        B4XTable1.CreateDataView($"c1 LIKE  '%${EditText1.text}%' OR c2  LIKE  '%${EditText1.text}%'  "$)   'c0 is 1st col, c1 is 2nd col,, c2 is 3rd, etc
        B4XTable1.Refresh   'comment this line if not needed
        Button2.Text="UnFilter" 
    Else
        B4XTable1.ClearDataView
        Button2.Text="Filter"
    End If
End Sub
 
Upvote 0
Top