cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
AshBose1
New Member

Reload and refresh Custom pcf control

Hi,

 

I have develop one custom PCF control for Dataset. My PCF control loads with dataset records and i can play around with control.

 

After playing with control, I want to refresh and reload the same PCF control by pragmatically from the control itself.

 

Thanks,

Ash

1 ACCEPTED SOLUTION

Accepted Solutions
carfup
Helper II
Helper II

Hi,

 

Basically you can do it where you want in your PCF control code.
By that I mean that as soon as you want to refresh / reload the control, you simply have to call again the rendering function of your pcf.
If you properly build it, the existing instance of the control will be cleaned and the new one will be there.

 

As sample, in my Quick Edit Form PCF control, as soon as we click on the refresh button i'm performing the following :

/**
	 * Function to refresh the content of the PCF
	 */
	private async refreshQEF(){
		this.unmountComponents();

		//disabling save button
		this._buttonsComponnent.setState({disabled : true});

		this.queryQuickViewFormData(this._quickViewFormId);
	}



Clément

View solution in original post

4 REPLIES 4
carfup
Helper II
Helper II

Hi,

 

Basically you can do it where you want in your PCF control code.
By that I mean that as soon as you want to refresh / reload the control, you simply have to call again the rendering function of your pcf.
If you properly build it, the existing instance of the control will be cleaned and the new one will be there.

 

As sample, in my Quick Edit Form PCF control, as soon as we click on the refresh button i'm performing the following :

/**
	 * Function to refresh the content of the PCF
	 */
	private async refreshQEF(){
		this.unmountComponents();

		//disabling save button
		this._buttonsComponnent.setState({disabled : true});

		this.queryQuickViewFormData(this._quickViewFormId);
	}



Clément

View solution in original post

Hi @AshBose1 , 

 

I agree with Clément, you have the full control of the code, and can rerender anytime.

In case you need to refresh the control because your data in dataset changed, you can simply call the dataset.refresh() method.

That will call your updateView function (with the new data), and there you need to rerender anyway.

Hope this helps.

 

Kind regards,

Diana

 

Hi Diana,

 

Thank you for suggestion.

 

I added and checked this in my PCF control, it called updateView function which reload my data only. I want to reload my whole PCF control with the HTML. 

 

For example if search anything in entity homegrid advanced search or advanced filter, it rerender the whole PCF control.

 

Thanks

Hi @AshBose2 , 

 

If you use pure TS/JS approach, you basically need to empty the "container" that you've got as parameter in the "init" function, and you need to render the grid each time the "updateView" is called.
Here is an example from sdk for a dataset pcf: https://docs.microsoft.com/en-us/powerapps/developer/component-framework/sample-controls/data-set-gr...

 

Usually, for a grid control I use react, since it would take too much work to make it from scratch. Here we need to call the ReactDOM.render everytime the updateView is called, letting react decide what it needs to refresh.
My code looks something like this:

public init(context: ComponentFramework.Context<IInputs>, notifyOutputChanged: () => void, state: ComponentFramework.Dictionary, container:HTMLDivElement)
	{
		this._container = container;			
		context.mode.trackContainerResize(true);
	}

public updateView(context: ComponentFramework.Context<IInputs>): void
	{	console.log(context.updatedProperties);
		this.renderGrid(context);
	}

My "renderGrid" function sets only the props, and calls

ReactDOM.render(React.createElement(ColorfulGrid, props ), this._container);

For the complete code, have a look to my github Repository:  https://github.com/brasov2de/ColorfulOptionsetGrid/tree/master/ColorfulOptionsetGrid

 

Hope it helps!

 

Kind regards,

Diana

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Are Your Ready?

Test your skills now with the Cloud Skill Challenge.

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Users online (74,337)