For  filter, sort along with search functionality

Chapter - 08

Visit to buy the book on Citizen Development https://go.citizendeveloper.codes/buynow

Code Snippet #9

For filter, sort along with search functionality

This code snippet combines several functions to update a context variable (tabReferrals) with a list of referrals that have been filtered, sorted, and searched based on certain criteria.

   UpdateContext(
        {
            tabReferrals: Filter(
                SortByColumns(
                    Search(
                        Referrals,
                        txtSearch.Value,
                        "nledu_name",
                        "nledu_referralemail",
                        "nledu_referralnotes"
                    ),
                    "nledu_referralstatus",
                    If(
                        locSortOrder,
                        SortOrder.Ascending,
                        SortOrder.Descending
                    )
                ),
                'Referrals (Views)'.'My Referrals'
            )
        }
    ); 

Explanation

  • Search Function:- Search(Referrals, txtSearch.Value, "nledu_name", "nledu_referralemail", "nledu_referralnotes"): This function searches through the Referrals data source (Microsoft Dataverse in this case) for records where the search string entered in txtSearch.Value matches any of the fields nledu_name, nledu_referralemail, or nledu_referralnotes.

  • SortByColumns Function:- SortByColumns(..., "nledu_referralstatus", If(locSortOrder, SortOrder.Ascending, SortOrder.Descending)): The results from the Search function are then sorted by the nledu_referralstatus field. The sort order (ascending or descending) is determined by the value of the locSortOrder context variable.

  • Filter Function:- Filter(..., 'Referrals (Views)'.'My Referrals'): The sorted list is further filtered to include only those records that meet the criteria defined by 'Referrals (Views)'.'My Referrals'. This might refer to a specific view or subset of the Referrals data, such as referrals belonging to the current user.

  • UpdateContext Function:- UpdateContext({ tabReferrals: ... }): This function updates the tabReferrals context variable with the results of the search, sort, and filter operations. Context variables are used in Power Apps to store and manage data locally on a screen.

In summary, this code snippet is performing a multi-step data manipulation process. It starts by searching the Referrals data source based on user input, sorts the results based on a specified field and order, filters these results based on a predefined condition, and finally stores this curated list of referrals in the tabReferrals context variable. This is a common pattern in Power Apps for creating dynamic, responsive user interfaces where the displayed data depends on user interactions such as search input and sorting preferences.

Happy #low-code learning

Visit: www.citizendeveloper.codes

Id: Chapter-08-CS00009

Category: Chapter 08

Dr. Amit Puri, Advisor and Consultant, Strengthening Digital Experiences, Modernize Cloud Journey with AI-Driven Transformation!

Code Snippet # 1
Chapter-06-CS00001 - Code Snippet # 1
Code Snippet # 8
Chapter-08-CS00008 - Code Snippet # 8
Code Snippet # 9
Chapter-06-CS00009 - Code Snippet # 9