Filter Gallery based on Screen1 dropdown selection and then allow search

时间:2017-04-06 17:13:30

标签: powerapps

My app contains a list of products carried by a chain of retail stores. I want the manager of each store to be able to select their store number on the home page and then see the gallery list of only the products in their store.

On Screen1 I have dropdown1, which lists the store numbers and then there is Button1 which should be pressed to navigate to BrowseGallery1, filtered by the store number selected in the dropdown.

My data source is a CDS called Products. There is a text field called StoreNum which has the store numbers, such as "111", "115", etc.

I tried putting the following in the OnSelect of Button1:

Navigate(BrowseScreen1,ScreenTransition.Fade,{StoreNum: 
Dropdown1.Selected.Value}), but that didn't work. It navigates to the 
page, but doesn't filter by StoreNum.

After I figure out the filter situation, I want the search box on BrowseScreen1 to search a few fields in the gallery, but only for that particular store. I currently have this in the "Items" section of BrowseGallery1:

Sort(If(IsBlank(TextSearchBox1.Text), Products, Filter(Products, TextSearchBox1.Text in Text(ItemNameWeight))), ItemNameWeight, Ascending)

That seems to search my ItemNameWeight field ok, but with no regard to store number.

I'd appreciate some help!

Thanks, Tony

1 个答案:

答案 0 :(得分:0)

当您将一个变量传递到导航选项中的屏幕时,它所做的一切,它只是在该屏幕中创建一个变量供您使用,而您在浏览屏幕中没有使用它。

首先让我们重命名变量,使其不与列名冲突:

Navigate(BrowseScreen1,ScreenTransition.Fade,{SelectedStore: Dropdown1.Selected.Value})

现在,让我们更新图库的Items属性中的函数,以便按StoreNum进行过滤,如下所示:

Sort(Filter(If(IsBlank(TextSearchBox1.Text), Products, Filter(Products, TextSearchBox1.Text in Text(ItemNameWeight))), SelectedStore = StoreNum), ItemNameWeight, Ascending)

应过滤所有具有正确编号的商店,然后按搜索框中的产品进行过滤。

如果要在数据库中搜索更多字段,可以添加更多过滤器命令。但是我建议为每种类型的搜索添加一个新屏幕,因为这样可以简化图库中的Items功能。

干杯。