cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
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
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
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
New Badges

New Solution Badges!

Check out our new profile badges recognizing authored solutions!

New Power Super Users

Congratulations!

We are excited to announce the Power Apps Super Users!

Power Apps Community Call

Power Apps Community Call: February

Did you miss the call? Check out the Power Apps Community Call here.

Microsoft Ignite

Microsoft Ignite

Join digitally, March 2–4, 2021 to explore new tech that's ready to implement. Experience the keynote in mixed reality through AltspaceVR!

Users online (39,834)