[英]Embedded power bi visuals filters not updating
I am trying to update the filters on some embedded visuals but it is not working.我正在尝试更新某些嵌入式视觉效果的过滤器,但它不起作用。 Also tried using this: await visual.updateFilters(FiltersOperations.Add, filters, FiltersLevel.Report);
也尝试使用这个: await visual.updateFilters(FiltersOperations.Add, filters, FiltersLevel.Report);
with no success.没有成功。 When using the FiltersOperations.Add
and FiltersLevel.Report
I get errors not able to find these, therefore tried to change them to their enum values, 2 for add, 0 for report.使用FiltersOperations.Add
和FiltersLevel.Report
时出现无法找到这些错误,因此尝试将它们更改为枚举值,2 表示添加,0 表示报告。
let embedConfiguration = {
accessToken: "@ViewBag.Token",
embedUrl: "@ViewBag.EmbedUrl",
id: "@ViewBag.Id",
pageName: pageName,
tokenType: 1,
type: 'visual',
visualName: visualName
};
// Get a reference to the HTML element that contains the embedded report.
let embedContainer = $('#'+embedContainerName)[0];
const basicFilter = {
$schema: "http://powerbi.com/product/schema#basic",
target: {
table: "Personskader",
column: "Disiplin"
},
operator: "In",
values: ["Insulation"],
filterType: 1
};
// Embed the visual.
let visual = powerbi.embed(embedContainer, embedConfiguration);
await visual.updateFilters(2, basicFilter);
}
The issue is with type.问题在于类型。 Second argument will be of type IFilter[].第二个参数将是 IFilter[] 类型。 So, pass it in array and it will work.所以,将它传递到数组中,它就会起作用。
You need to import powerbi-models
when you are using FiltersOperations.Add
this is the reason you are getting errors.You can specify models.FiltersOperations.Add
and this works.您在使用 FiltersOperations 时需要导入powerbi-models
FiltersOperations.Add
这就是您收到错误的原因。您可以指定models.FiltersOperations.Add
并且这有效。
await visual.updateFilters(models.FiltersOperations.Add, [basicFilter]);
You can play with any Api and test it for your own report here https://playground.powerbi.com/en-us/dev-sandbox你可以玩任何 Api 并在这里测试你自己的报告https://playground.powerbi.com/en-us/dev-sandbox
References: https://learn.microsoft.com/javascript/api/overview/powerbi/control-report-filters参考资料: https://learn.microsoft.com/javascript/api/overview/powerbi/control-report-filters
Still can't seem to make it work.似乎仍然无法让它发挥作用。 Can you see any errors in the code?你能看到代码中的任何错误吗? I have updated all nuget packages, CSS, JS etc. so I'm lost...我已经更新了所有 nuget 包、CSS、JS 等,所以我迷路了……
@section Scripts {
<script src="/lib/powerbi-client/dist/powerbi.min.js"></script>
<script>
// Get models. models contains enums that can be used.
models = window['powerbi-client'].models;
async function embedVisual(pageName, visualName, embedContainerName) {
let embedConfiguration = {
accessToken: "@ViewBag.Token",
embedUrl: "@ViewBag.EmbedUrl",
id: "@ViewBag.Id",
pageName: pageName,
tokenType: 1,
type: 'visual',
visualName: visualName
};
// Get a reference to the HTML element that contains the embedded report.
let embedContainer = $('#'+embedContainerName)[0];
const basicFilter = {
$schema: "http://powerbi.com/product/schema#basic",
target: {
table: "Personskader",
column: "Disiplin"
},
operator: "In",
values: ["Insulation"],
filterType: models.FilterType.Basic
};
// Embed the visual.
let visual = powerbi.embed(embedContainer, embedConfiguration);
await visual.updateFilters(models.FiltersOperations.Add,[basicFilter]);
}
embedVisual("ReportPageName", "VisualName", "embedContainer"); //Not real values
</script>
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.