Search code examples
searchgallerypowerapps

Power Apps Searching on multiple columns in Gallery


I have a gallery that is linked to a SharePoint List. I want to be able to search 3 fields with the 3 search boxes. Now I made 3 search boxes for ID, Name, and Last Name. I can get it working when searching for 1 field but when I try to modify it to search across multiple fields, it breaks.

Filter(tbl_mas_employee,StartsWith(Title,txtEmpCode.Text))

What modifications need to be made to the above function to be able to use the 3 search boxes? Picture


Solution

  • Try this:

    Filter(SHAREPOINT_LIST,
        Or(
            StartsWith(spColumnName1, txtBox1.Text),
            StartsWith(spColumnName2, txtBox2.Text),
            StartsWith(spColumnName3, txtBox3.Text)
        )
    )
    

    Consider doing this differently for performance and delegation reasons.

    1. OnVisible of the screen, create a collection from the Sharepoint List
    ClearCreate(colRecords,
        Filter(SHAREPOINT_LIST,
            condition = someValue
        )
    )
        
    
    1. Have 1 textbox for searching (txtSearch)

      • Set its HintText property to something like Search by Title, column2, etc.
      • Set DelayOutput property to true
    2. Set the gallery Items property to:

    Filter(colRecords,
        Or(
            txtSearch.Text in Title,
            txtSearch.Text in column2,
            etc...
        )
    )
    

    Then its really easy to add another column. Also the user experience is quite nice.