Search code examples
matrixpowerbiselectionpowerbi-custom-visuals

power bi - custom visual - matrix selection not update other visual


this same question with power bi - forum - developer

i try create selection with my matrix custom visual, but that make error on other visual

this is my transform, using builder withMatrixNode

function visualTransform(options: VisualUpdateOptions, host: IVisualHost): DataViewModel {

let dataViews = options.dataViews[0];
var rows = dataViews.matrix.rows;
let listSelectionId: DataListSelection[] = [];
let selectionIdBuilder = host.createSelectionIdBuilder();

rows.root.children.forEach(x => {
    listSelectionId.push({
        value: x.value,
        selectionId: selectionIdBuilder.withMatrixNode(x, rows.levels).createSelectionId()
    });

    if (x.children)
        x.children.forEach(z => {
            listSelectionId.push({
                value: z.value,
                selectionId: selectionIdBuilder.withMatrixNode(z, rows.levels).createSelectionId()
            });
            if (z.children)
                z.children.forEach(a => {
                    listSelectionId.push({
                        value: a.value,
                        selectionId: selectionIdBuilder.withMatrixNode(a, rows.levels).createSelectionId()
                    });

                })
        })
});
return {
    dataPoints: listSelectionId
}

}

I'm already add click listener to get selection Id and make it selected in manager, and this is the console log enter image description here

but but my page always got error in other visual: enter image description here

what wrong with my selection code? and one more question, I'm already declare selectcallback in my manager but never called when other visual make selection

this.selectionManager = this.host.createSelectionManager();
    console.log('constructor allow interaction', this.host.allowInteractions);
    this.selectionManager.registerOnSelectCallback(() => {
        console.log('selection manager callback', this.selectionManager.getSelectionIds());
    });
    this.selectionIdBuilder = options.host.createSelectionIdBuilder();

Solution

  • solve this with remove let

    let selectionIdBuilder = host.createSelectionIdBuilder();