cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
MariusSolend
Level: Powered On

Filtering a dataset does not work?

I have som issues with filtering a dataset and I'm wondering if I'm doing anything wrong. I've broken it down to something simple. Please view the code below. It only uses the default dataset with the three records which all contains the value "val" in the three columns "name", "telephone1" and "address1_city". I apply a filter to the dataset and then I do a refresh on the dataset and then I expect the updateView to get called again with the new dataset. But this does not seem to happen. Given the code below this is the output I have in my console. the updateView only runs once and does not filter my dataset.

 

I am copying @mtanguy  in here because I see on these forumn that you have some experience in this.

 

EDIT: Or is just buggy behaviour in the testharness and it would work in a D365 instance? Its a hassle to upload the solution to D365 eveytime you want to try a change.

 

Capture.PNG

 

 

 

 

 

 

init function:

 

 

public init(context: ComponentFramework.Context<IInputs>, notifyOutputChanged: () => void, state: ComponentFramework.Dictionary, container: HTMLDivElement) {
	console.log("init function called");
	context.mode.trackContainerResize(true);
}

 

 

 

updateView function:

 

 

public updateView(context: ComponentFramework.Context<IInputs>): void {
		console.log("updateView function called");
		
		const existingFilter = context.parameters.GridSampleData.filtering.getFilter();

		if (!existingFilter) {
			console.log("No existing filter. Setting filter...");
			context.parameters.GridSampleData.filtering.setFilter({
				filterOperator: 0,
				conditions: [{
					attributeName: "name",
					conditionOperator: 1, // NotEquals
					value: "val",
				}],
				filters: [],
			});

			context.parameters.GridSampleData.refresh();

		} else {
			console.log("Filter exists");
		}

		for(const recordId of context.parameters.GridSampleData.sortedRecordIds) {
			const record = context.parameters.GridSampleData.records[recordId];
			console.log(record.getFormattedValue("name"));
		}
	}

 

 

 

2 REPLIES 2
Community Support Team
Community Support Team

Re: Filtering a dataset does not work?

Hi @MariusSolend ,

Could you please share more details about your Manifet.Input.xml file?

Do you want to developer a code component for Model-Driven app for canvas app?

 

Currently, the Refresh function under the DataSet is only available for Model-Driven app. If you are developing this code component for a canvas app, the following formula would not work:

context.parameters.GridSampleData.refresh();

Pease check the following article for more details:

https://docs.microsoft.com/en-us/powerapps/developer/component-framework/reference/dataset/refresh

 

In addition, the updateView function would only be called when any value in the property bag (defined in your Manifet.Input.xml file) has been changed. Please check if the property value has been changed after executing your filtering formula.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
MariusSolend
Level: Powered On

Re: Filtering a dataset does not work?

This is for a modeldriven app. And i just run this in the test harness. I dont have a property in my manifest file. I only have a dataset called GridSampleData like this:

<data-set name="GridSampleData" display-name-key="GridSampleData" description-key="GridSampleData" cds-data-set-options="displayCommandBar:true;displayViewSelector:true;displayQuickFindSearch:true">
</data-set>

 

Helpful resources

Announcements
thirdimage

Power Apps Super User Class of 2020

Check it out!

thirdimage

New Badges

Check it out!

thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

SecondImage

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Users online (5,156)