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 theReferrals
data source (Microsoft Dataverse in this case) for records where the search string entered intxtSearch.Value
matches any of the fieldsnledu_name
,nledu_referralemail
, ornledu_referralnotes
. -
SortByColumns Function:-
SortByColumns(..., "nledu_referralstatus", If(locSortOrder, SortOrder.Ascending, SortOrder.Descending))
: The results from theSearch
function are then sorted by thenledu_referralstatus
field. The sort order (ascending or descending) is determined by the value of thelocSortOrder
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 theReferrals
data, such as referrals belonging to the current user. -
UpdateContext Function:-
UpdateContext({ tabReferrals: ... })
: This function updates thetabReferrals
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
Amit Puri, Advisor and Consultant, Strengthening Digital Experiences, Modernize Cloud Journey with AI-Driven Transformation!