Hello Friends,
Welcome back with another post on PowerApps. In our last post, we learned about the Show/Hide of columns in DataTable. Here is the link of the post.
If we wish to have the same feature using Gallery, then would it be possible? Because, in Gallery, there are no columns? The answer is YES. We can achieve the same functionality using Gallery as well. Today, we will learn about show/hide of column in PowerApps Gallery dynamically. The objective is to create an App where user can-
- Select the columns to display as per it's choice
- Select any of the available view and the columns should display based upon that view. Also, the data must get filter accordingly
- Apply additional filter based upon a particular column
- Apply additional filter using a Free Text Search
This is what, we are going to build-
Let's start-
- We already have the screen designed last time in our last post (see link above). We are going to use the same screen.
- Click on ellipses (3 dots) ahead to "ScreenHome" and select "Duplicate Screen".
- It will create a duplicate screen with name as "ScreenHome_1" including all the controls with suffixed as "_1".
- Now, rename the screen from "ScreenHome_1" to "ScreenGallery". Renaming is also simple.
- Click on ellipses (3 dots) ahead to "ScreenHome_1" and select "Rename".
- Now, we can see that DataTable_Result is also got renamed as "DataTable_Result_1". Copy the functions written on below properties for DataTable_Result_1.
- Height
- Items
- Width
- X
- Y
- Visible property function for any one column.
- Now, remove the DataTable_Result_1 control.
- From here, we will first add "Text label" that will serve the purpose of Gallery Headers. Then we will add a Gallery (Blank vertical gallery). Later, we will add Labels inside gallery template that will serve the purpose to display the items data.
- Let's resume the process.
- Add a Text label and update the properties as below-
- Name: Label_Header_ID
- Text: ID
- BorderColor: RGBA(255, 255, 255, 1)
- BorderThickness: 1
- Color: RGBA(255, 255, 255, 1)
- Fill: RGBA(0, 18, 107, 1)
- Height: 40
- X: Label_SelectView_1.X
- Y: Label_SelectColumns_1.Y+Label_SelectColumns_1.Height+50
- Visible & Width properties will be updated later on.
- Lastly, from the right side properties pane, set "Text Alignment" to "Align center"
- Add another Text label and update the properties as below. (Better, make a duplicate copy of the "ID" label so that you have to set only 4 properties rather than these many-
- Name: Label_Header_Title
- Text: Title
- X: Label_Header_ID.X+Label_Header_ID.Width
- Y: Label_Header_ID.Y
- Visible & Width properties will be updated later on
- Here, we have changed the way to define the X & Y properties. Now, onwards, only Name, Text & X properties will be updated. Every next label will have X property a the sum of X & Width property of previous label. Rest will remain common.
- Make a duplicate copy of this "Title" label and update properties as below-
- Name: Label_Header_First_Name
- Text: First Name
- X: Label_Header_Title.X+Label_Header_Title.Width
- Visible & Width properties will be updated later on
- Make a duplicate copy of this "First Name" label and update properties as below-
- Name: Label_Header_Last_Name
- Text: Last Name
- X: Label_Header_First_Name.X+Label_Header_First_Name.Width
- Visible & Width properties will be updated later on
- Make a duplicate copy of this "Last Name" label and update properties as below-
- Name: Label_Header_Date_Of_Joining
- Text: Date Of Joining
- X: Label_Header_Last_Name.X+Label_Header_Last_Name.Width
- Visible & Width properties will be updated later on
- Make a duplicate copy of this "Date Of Joining" label and update properties as below-
- Name: Label_Header_Salary
- Text: Salary
- X: Label_Header_Date_Of_Joining.X+Label_Header_Date_Of_Joining.Width
- Visible & Width properties will be updated later on
- Make a duplicate copy of this "Salary" label and update properties as below-
- Name: Label_Header_Designation
- Text: Designation
- X: Label_Header_Salary.X+Label_Header_Salary.Width
- Visible & Width properties will be updated later on
- Make a duplicate copy of this "Designation" label and update properties as below-
- Name: Label_Header_Experience
- Text: Experience
- X: Label_Header_Designation.X+Label_Header_Designation.Width
- Visible & Width properties will be updated later on
- Finally, the outcome will be-
- Now, we will add a "Blank vertical gallery" and update it's properties as below-
- Name: BVG_Gallery_Result
- X: Label_SelectView_1.X
- Y: Label_Header_ID.Y+Label_Header_ID.Height
- Width: ScreenGallery.Width
- Height: ScreenGallery.Height-BVG_Gallery_Result.Y
- TemplateSize: 50
- TemplatePadding: 0
- BorderThickness: 1
- Now, we will update the "Items" property of this gallery. We have already copied the function for Items property from the DataTable (we deleted in beginning). The same function, we need to paste it over here.
Switch( Dropdown_SelectView_1.SelectedText.ViewName, "All Employees", Filter( EmployeeInfo, Experience.Value in If( Radio_SelectExperience_1.SelectedText.Experience = "All", Experience.Value, Radio_SelectExperience_1.SelectedText.Experience ) && (Trim(TextInput_Search_1.Text) in 'First Name' || Trim(TextInput_Search_1.Text) in 'Last Name' || Trim(TextInput_Search_1.Text) in Designation.Value || Trim(TextInput_Search_1.Text) in Experience.Value || Upper(Title) = Upper(Trim(TextInput_Search_1.Text))) || Text( 'Date Of Joining', "m/d/yyyy", "en-US" ) = Text( Trim(TextInput_Search_1.Text), "m/d/yyyy", "en-US" ) || Text(Trim(Salary)) = Trim(TextInput_Search_1.Text) ), "Software Engineer", Filter( EmployeeInfo, "Software Engineer" in Designation.Value, Experience.Value in If( Radio_SelectExperience_1.SelectedText.Experience = "All", Experience.Value, Radio_SelectExperience_1.SelectedText.Experience ) && (Trim(TextInput_Search_1.Text) in 'First Name' || Trim(TextInput_Search_1.Text) in 'Last Name' || Trim(TextInput_Search_1.Text) in Designation.Value || Trim(TextInput_Search_1.Text) in Experience.Value || Upper(Title) = Upper(Trim(TextInput_Search_1.Text))) || Text( 'Date Of Joining', "m/d/yyyy", "en-US" ) = Text( Trim(TextInput_Search_1.Text), "m/d/yyyy", "en-US" ) || Text(Trim(Salary)) = Trim(TextInput_Search_1.Text) ), "Module Lead", Filter( EmployeeInfo, "Module Lead" in Designation.Value, Experience.Value in If( Radio_SelectExperience_1.SelectedText.Experience = "All", Experience.Value, Radio_SelectExperience_1.SelectedText.Experience ) && (Trim(TextInput_Search_1.Text) in 'First Name' || Trim(TextInput_Search_1.Text) in 'Last Name' || Trim(TextInput_Search_1.Text) in Designation.Value || Trim(TextInput_Search_1.Text) in Experience.Value || Upper(Title) = Upper(Trim(TextInput_Search_1.Text))) || Text( 'Date Of Joining', "m/d/yyyy", "en-US" ) = Text( Trim(TextInput_Search_1.Text), "m/d/yyyy", "en-US" ) || Text(Trim(Salary)) = Trim(TextInput_Search_1.Text) ), "Project Manager", Filter( EmployeeInfo, "Project Manager" in Designation.Value, Experience.Value in If( Radio_SelectExperience_1.SelectedText.Experience = "All", Experience.Value, Radio_SelectExperience_1.SelectedText.Experience ) && (Trim(TextInput_Search_1.Text) in 'First Name' || Trim(TextInput_Search_1.Text) in 'Last Name' || Trim(TextInput_Search_1.Text) in Designation.Value || Trim(TextInput_Search_1.Text) in Experience.Value || Upper(Title) = Upper(Trim(TextInput_Search_1.Text))) || Text( 'Date Of Joining', "m/d/yyyy", "en-US" ) = Text( Trim(TextInput_Search_1.Text), "m/d/yyyy", "en-US" ) || Text(Trim(Salary)) = Trim(TextInput_Search_1.Text) ), "Program Manager", Filter( EmployeeInfo, "Program Manager" in Designation.Value, Experience.Value in If( Radio_SelectExperience_1.SelectedText.Experience = "All", Experience.Value, Radio_SelectExperience_1.SelectedText.Experience ) && (Trim(TextInput_Search_1.Text) in 'First Name' || Trim(TextInput_Search_1.Text) in 'Last Name' || Trim(TextInput_Search_1.Text) in Designation.Value || Trim(TextInput_Search_1.Text) in Experience.Value || Upper(Title) = Upper(Trim(TextInput_Search_1.Text))) || Text( 'Date Of Joining', "m/d/yyyy", "en-US" ) = Text( Trim(TextInput_Search_1.Text), "m/d/yyyy", "en-US" ) || Text(Trim(Salary)) = Trim(TextInput_Search_1.Text) )
)- Now, we will add Text labels to show the items data. Click on "Edit gallery" icon shown in gallery.
- It will change the template to edit mode.
- Now add "Text label" and update properties as below-
- Name: Label_Value_ID
- Text: ThisItem.ID
- BorderThickness: 1
- Height: BVG_Gallery_Result.TemplateHeight
- X: Label_Header_ID.X
- Y: 0
- Visible: Label_Header_ID.Visible
- Width: Label_Header_ID.Width
- Add "Text label" and update properties as below-
- Name: Label_Value_Title
- Text: ThisItem.Title
- BorderThickness: Label_Value_ID.BorderThickness
- Height: BVG_Gallery_Result.TemplateHeight
- X: Label_Header_Title.X
- Y: Label_Value_ID.Y
- Visible: Label_Header_Title.Visible
- Width: Label_Header_Title.Width
- Make a duplicate copy of "Title" value label and update properties as below-
- Name: Label_Value_First_Name
- Text: ThisItem.'First Name'
- X: Label_Header_First_Name.X
- Visible: Label_Header_First_Name.Visible
- Width: Label_Header_First_Name.Width
- Make a duplicate copy of "First Name" value label and update properties as below-
- Name: Label_Value_Last_Name
- Text: ThisItem.'Last Name'
- X: Label_Header_Last_Name.X
- Visible: Label_Header_Last_Name.Visible
- Width: Label_Header_Last_Name.Width
- Make a duplicate copy of "Last Name" value label and update properties as below-
- Name: Label_Value_Date_Of_Joining
- Text: ThisItem.'Date Of Joining'
- X: Label_Header_Date_Of_Joining.X
- Align: Align.Right
- Visible: Label_Header_Date_Of_Joining.Visible
- Width: Label_Header_Date_Of_Joining.Width
- Make a duplicate copy of "Date Of Joining" value label and update properties as below-
- Name: Label_Value_Salary
- Text: Text(ThisItem.Salary,"#00,000.00")
- X: Label_Header_Salary.X
- Align: Align.Right
- Visible: Label_Header_Salary.Visible
- Width: Label_Header_Salary.Width
- Make a duplicate copy of "Salary" value label and update properties as below-
- Name: Label_Value_Designation
- Text: ThisItem.Designation.Value
- X: Label_Header_Designation.X
- Align: Align.Left
- Visible: Label_Header_Designation.Visible
- Width: Label_Header_Designation.Width
- Make a duplicate copy of "Designation" value label and update properties as below-
- Name: Label_Value_Experience
- Text: ThisItem.Experience.Value
- X: Label_Header_Experience.X
- Align: Align.Left
- Visible: Label_Header_Experience.Visible
- Width: Label_Header_Experience.Width
- The outcome is here.
- Now, we will update the Visible & Width properties of Header Labels as below.
- Update the Width & Visible property of each header as below-
- Control: Label_Header_ID
- Visible: CountRows(
Filter( collCurrentDisplayColumnsWithOrder, Substitute( ColumnName, "_x0020_", " " ) = "ID" ) ) > 0
- Width: If(
CountRows( Filter( collCurrentDisplayColumnsWithOrder, Substitute( ColumnName, "_x0020_", " " ) = "ID" ) ) > 0, BVG_Gallery_Result.Width / CountRows(collCurrentDisplayColumnsWithOrder), 0 )
- Control: Label_Header_Title
- Visible: CountRows(
Filter( collCurrentDisplayColumnsWithOrder, Substitute( ColumnName, "_x0020_", " " ) = "Title" ) ) > 0
- Width: If(
CountRows( Filter( collCurrentDisplayColumnsWithOrder, Substitute( ColumnName, "_x0020_", " " ) = "Title" ) ) > 0, BVG_Gallery_Result.Width / CountRows(collCurrentDisplayColumnsWithOrder), 0 )
- Control: Label_Header_First_Name
- Visible: CountRows(
Filter( collCurrentDisplayColumnsWithOrder, Substitute( ColumnName, "_x0020_", " " ) = "First Name" ) ) > 0
- Width: If(
CountRows( Filter( collCurrentDisplayColumnsWithOrder, Substitute( ColumnName, "_x0020_", " " ) = "First Name" ) ) > 0, BVG_Gallery_Result.Width / CountRows(collCurrentDisplayColumnsWithOrder), 0 )
- Control: Label_Header_Last_Name
- Visible: CountRows(
Filter( collCurrentDisplayColumnsWithOrder, Substitute( ColumnName, "_x0020_", " " ) = "Last Name" ) ) > 0
- Width: If(
CountRows( Filter( collCurrentDisplayColumnsWithOrder, Substitute( ColumnName, "_x0020_", " " ) = "Last Name" ) ) > 0, BVG_Gallery_Result.Width / CountRows(collCurrentDisplayColumnsWithOrder), 0 )
- Control: Label_Header_Date_Of_Joining
- Visible: CountRows(
Filter( collCurrentDisplayColumnsWithOrder, Substitute( ColumnName, "_x0020_", " " ) = "Date Of Joining" ) ) > 0
- Width: If(
CountRows( Filter( collCurrentDisplayColumnsWithOrder, Substitute( ColumnName, "_x0020_", " " ) = "Date Of Joining" ) ) > 0, BVG_Gallery_Result.Width / CountRows(collCurrentDisplayColumnsWithOrder), 0 )
- Control: Label_Header_Salary
- Visible: CountRows(
Filter( collCurrentDisplayColumnsWithOrder, Substitute( ColumnName, "_x0020_", " " ) = "Salary" ) ) > 0
- Width: If(
CountRows( Filter( collCurrentDisplayColumnsWithOrder, Substitute( ColumnName, "_x0020_", " " ) = "Salary" ) ) > 0, BVG_Gallery_Result.Width / CountRows(collCurrentDisplayColumnsWithOrder), 0 )
- Control: Label_Header_Designation
- Visible: CountRows(
Filter( collCurrentDisplayColumnsWithOrder, Substitute( ColumnName, "_x0020_", " " ) = "Designation" ) ) > 0
- Width: If(
CountRows( Filter( collCurrentDisplayColumnsWithOrder, Substitute( ColumnName, "_x0020_", " " ) = "Designation" ) ) > 0, BVG_Gallery_Result.Width / CountRows(collCurrentDisplayColumnsWithOrder), 0 )
- Control: Label_Header_Experience
- Visible: CountRows(
Filter( collCurrentDisplayColumnsWithOrder, Substitute( ColumnName, "_x0020_", " " ) = "Experience" ) ) > 0
- Width: If(
CountRows( Filter( collCurrentDisplayColumnsWithOrder, Substitute( ColumnName, "_x0020_", " " ) = "Experience" ) ) > 0, BVG_Gallery_Result.Width / CountRows(collCurrentDisplayColumnsWithOrder), 0 )
- That's all. Now, you can save the app, publish it and play it. Before that, I have to add one button on previous screen (ScreenHome) so that I can navigate to the Gallery screen.
- Here we go. Start playing the app.
- Default load
- Removed "Date Of Joining" column
- Filter on Experience
- Free Text Search
- Changed View
- Selected All Columns
- This way, you can achieve the Show/Hide feature using Gallery as well.
- For me, the number of columns were less, therefore, I am able to manage using Screen Width / No of Columns. In case, the number of columns are more, change the logic of Width accordingly.
- Next, you may add Export To Excel feature as well.
With this, I am concluding this post.
Happy Coding !!!
Will see you again with some new topics.
Stay Safe !
Stay Healthy !
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.