PowerApps中排序Choice字段时如何抑制错误红色横幅?
解决PowerApp中Choice字段排序出现错误横幅的问题
问题原因
SharePoint的Choice字段是复合数据类型(包含Value、Id等属性),而SortByColumns函数通过字符串字段名(如"Status")排序时,无法正确解析复合字段的排序逻辑,因此会抛出错误提示——即便实际排序功能能运行,错误横幅也会持续显示。
解决方案
方法一:直接针对Choice字段的Value属性排序(推荐)
修改Status列标题的OnSelect代码,用Sort函数替代SortByColumns,直接指定排序的属性:
Set(gvSortDesc, !gvSortDesc); Set(gvSortCol, "Status"); Sort( colGalleryContents, Status.Value, If(gvSortDesc, SortOrder.Descending, SortOrder.Ascending) )
这种方式让PowerApps明确知道要基于Choice字段的文本值排序,从根源消除错误。
方法二:提前在集合中提取Choice字段的文本值
如果需要保留SortByColumns和变量控制排序列的逻辑,可以在加载集合时,给Choice字段新增一个文本类型的计算列:
- 修改集合加载代码(比如在App的
OnStart或屏幕的OnVisible中):
ClearCollect( colGalleryContents, AddColumns( 你的SharePoint列表名称, "StatusValue", Status.Value ) )
- 修改Status列标题的
OnSelect代码,改用新的文本列排序:
Set(gvSortDesc, !gvSortDesc); Set(gvSortCol, "StatusValue"); SortByColumns( colGalleryContents, gvSortCol, If(gvSortDesc, SortOrder.Descending, SortOrder.Ascending) )
临时隐藏错误横幅(不推荐)
如果暂时不想修改排序逻辑,可全局抑制错误显示,但这会掩盖其他潜在问题,谨慎使用:
- 在App的
OnStart中添加:
Set(gvSuppressErrors, true);
- 在App的
Error属性中设置:
If(gvSuppressErrors, Blank(), Error)
内容的提问来源于stack exchange,提问作者Our Man in Bananas
相关产品推荐
相关产品推荐

