For  toggle a filter functionality

Chapter - 08

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

Code Snippet #6

For toggle a filter functionality

This code snippet is designed to toggle a filter on a collection of referral data based on a context variable (locFiltered). It updates another context variable (tabReferrals) with a filtered subset of the Referrals data source, based on the value of locFiltered.

   UpdateContext({locFiltered: !locFiltered});
    If(
        locFiltered,
        UpdateContext(
            {
                tabReferrals: Filter(
                    Referrals,
                    'Referrals (Views)'.'My Referrals',
                    ThisRecord.'Referral Status' = 'Referral Status (Referrals)'.'Application submitted'
                )
            }
        ),
        UpdateContext(
            {
                tabReferrals: Filter(
                    Referrals,
                    'Referrals (Views)'.'My Referrals'
                )
            }
        );
    );

Explanation

  • Toggling the Filter State:- UpdateContext({locFiltered: !locFiltered});: This line toggles the value of the context variable locFiltered. If locFiltered is currently true, it becomes false, and vice versa. This variable is likely used to track whether a specific filter is applied to the referral data.

  • Conditional Filtering of Referrals:- The If statement checks the state of locFiltered:
    • If locFiltered is true, it applies a specific filter to the Referrals data source:
      • UpdateContext({ tabReferrals: Filter(Referrals, 'Referrals (Views)'.'My Referrals', ThisRecord.'Referral Status' = 'Referral Status (Referrals)'.'Application submitted') }): This updates the tabReferrals context variable with referral records where the status is ‘Application submitted’. It assumes that ‘Referrals (Views)’.’My Referrals’ is a predefined view or condition within the Referrals data source.
    • If locFiltered is false, it applies a more general filter:
      • UpdateContext({ tabReferrals: Filter(Referrals, 'Referrals (Views)'.'My Referrals') }): This updates tabReferrals with all referral records that meet the ‘My Referrals’ condition or view, regardless of their referral status.
  • Usage of UpdateContext: This UpdateContext function is used to create or update a context variable within the current screen of a Power Apps application. Context variables are temporary and local to the screen they are set in.

In summary, this code snippet is used to toggle between two states of a filtered list of referrals: one where only referrals with the status ‘Application submitted’ are shown, and another where all referrals under ‘My Referrals’ are shown. This functionality is useful in scenarios where users need to switch views or filters in a list, such as in dashboards or data management interfaces.

Happy #low-code learning

Visit: www.citizendeveloper.codes

Id: Chapter-08-CS00006

Category: Chapter 08

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

Code Snippet # 8
Chapter-06-CS00008 - Code Snippet # 8
Code Snippet # 7
Chapter-08-CS00007 - Code Snippet # 7
Code Snippet # 4
Chapter-06-CS00004 - Code Snippet # 4