cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
m_jeppesen
Helper I
Helper I

Filter gallery optionset based on textinput

Hi

I have a CDS/Dataverse datasource, and in a gallery I display a table/entity, with some fields, here among an optionset.

I want to be able to filter the gallery based on a textinput field, and the field that should be filteren on is the optionset field.

 

So if we on the entity/table have an optionset with possible values (Bathroom, Storage, Livingroom, Enterence), if we then enter "room" in the textinput, the gallery will be filtered to only show records that have the opstionset set to "Bathroom" or "Livingroom".

1 ACCEPTED SOLUTION

Accepted Solutions
v-xiaochen-msft
Community Support
Community Support

Hi @m_jeppesen ,

 

Firstly, the data type of the optionset field is not text. But the data type of textinput control is text. So you could not use string to search for the record you want.

Therefore, it is difficult to use the textinput control directly to filter the optionset field.

 

Secondly, dropdown control supports optionsetfield. So you could use the dropdown control to filter the optionset field.

 

So , I suggest you set the default value of dropdown control by judging the input of textinput control.

For example:

When typing "Bathroom" into the textinput control, the dropdown control selects the "Bathroom" option by default.

Gallery filters records through the item selected by the dropdown control.

 

Finally, hide the dropdown control. The textinput control can filter records indirectly.

 

According to your description ,I've made a test for your reference.The point is to use three controls to meet your needs. They are textinput control, dropdown control and gallery control.

1\ This is my entity Test2S

v-xiaochen-msft_0-1608019937799.jpeg

 

 

2\ Add a textinput control TextInput1.

 

3\ Add a dropdown control Dropdown1 and set its Items property to:

Choices(Test2S.Optionset)

 

Set Dropdown1 s Default property to:

If(

    TextInput1.Text = "Bathroom",

    Last(

        FirstN(

            Test2S,

            1

        )

    ).Optionset,

    TextInput1.Text = "Storage",

    Last(

        FirstN(

            Test2S,

            2

        )

    ).Optionset,

    TextInput1.Text = "Livingroom",

    Last(

        FirstN(

            Test2S,

            3

        )

    ).Optionset,

    TextInput1.Text = "Enterence",

    Last(

        FirstN(

            Test2S,

            4

        )

    ).Optionset

)

 

Set Dropdown1 s Visible property to:

false

 

4\ Add a gallery control and set its Items property to:

Filter(Test2S,Optionset=Dropdown1.Selected.Value)

 

5\ The result is as follows:

v-xiaochen-msft_1-1608019937802.png

 

v-xiaochen-msft_2-1608019937804.png

 

 

In addition, I suggest you use the drop-down control directly instead of the textinput control.

The advantage is that the code is simpler and easier to maintain.

 

Best Regards,

Wearsky

View solution in original post

2 REPLIES 2
v-xiaochen-msft
Community Support
Community Support

Hi @m_jeppesen ,

 

Firstly, the data type of the optionset field is not text. But the data type of textinput control is text. So you could not use string to search for the record you want.

Therefore, it is difficult to use the textinput control directly to filter the optionset field.

 

Secondly, dropdown control supports optionsetfield. So you could use the dropdown control to filter the optionset field.

 

So , I suggest you set the default value of dropdown control by judging the input of textinput control.

For example:

When typing "Bathroom" into the textinput control, the dropdown control selects the "Bathroom" option by default.

Gallery filters records through the item selected by the dropdown control.

 

Finally, hide the dropdown control. The textinput control can filter records indirectly.

 

According to your description ,I've made a test for your reference.The point is to use three controls to meet your needs. They are textinput control, dropdown control and gallery control.

1\ This is my entity Test2S

v-xiaochen-msft_0-1608019937799.jpeg

 

 

2\ Add a textinput control TextInput1.

 

3\ Add a dropdown control Dropdown1 and set its Items property to:

Choices(Test2S.Optionset)

 

Set Dropdown1 s Default property to:

If(

    TextInput1.Text = "Bathroom",

    Last(

        FirstN(

            Test2S,

            1

        )

    ).Optionset,

    TextInput1.Text = "Storage",

    Last(

        FirstN(

            Test2S,

            2

        )

    ).Optionset,

    TextInput1.Text = "Livingroom",

    Last(

        FirstN(

            Test2S,

            3

        )

    ).Optionset,

    TextInput1.Text = "Enterence",

    Last(

        FirstN(

            Test2S,

            4

        )

    ).Optionset

)

 

Set Dropdown1 s Visible property to:

false

 

4\ Add a gallery control and set its Items property to:

Filter(Test2S,Optionset=Dropdown1.Selected.Value)

 

5\ The result is as follows:

v-xiaochen-msft_1-1608019937802.png

 

v-xiaochen-msft_2-1608019937804.png

 

 

In addition, I suggest you use the drop-down control directly instead of the textinput control.

The advantage is that the code is simpler and easier to maintain.

 

Best Regards,

Wearsky

m_jeppesen
Helper I
Helper I

Thanks @v-xiaochen-msft 
Not the most smooth solution, but that's really not your fault 😉

Helpful resources

Announcements
PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Top Solution Authors
Top Kudoed Authors
Users online (2,145)