Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
m1nato78lol
New Member

How to get initial state in React Power BI cutom component with sync

I have a custom component ( DatePicker ) written in React. How to get initial data for multiple pages if components are synchronized via "supportsSynchronizingFilterState". I need to get start date and end date. If I switch between pages, only the constructor is called

 

2 REPLIES 2
jaweher899
Super User
Super User

You can use the filter state property of the custom component to retrieve the initial start date and end date. The filter state property is updated when the user changes the values in the date picker and can be used to pass the values to other components in the report.

Here's an example of how you can retrieve the initial start and end dates in the constructor of the custom component:

constructor(props) {
super(props);
const filterState = props.filterState;

let startDate = null;
let endDate = null;

if (filterState) {
startDate = filterState.startDate;
endDate = filterState.endDate;
}

this.state = {
startDate,
endDate
};
}

In this example, the filterState is passed as a property to the custom component and the start and end dates are retrieved from the filterState. If the filterState is not available, the start and end dates are set to null. The start and end dates are then set in the component's state.

I can't get filter from other page. When i have sync between pages with same dataset, update don't trigger. So i can't get jsonFilter in my constructor. I solving this by force tr igger update by applying new random json filter. This trigger calls update, where i can get jsonFilter and set new state for start and end dates

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors