Select to view content in your preferred language

Clicking Feature Resets Filter

133
3
Jump to solution
Monday
TristanJonas
Occasional Contributor

Hello all, I made a custom filter widget and my filters keep disappearing when I interact with the map, here's the workflow that triggers the issue:

1. First I apply a filter for Ohio with my custom widget
2. Then I click a feature to test the persistence
3. Then I clear the filters so it shows the full map again
4. Then I apply a Michigan filter with custom widget
5. After I click a Michigan feature, it unexpectedly reverts to the Ohio filter.

This is obviously really frustrating, if I want to switch between different filters and examine the data in the map it will keep reverting back to the first filter I clicked a feature from. So clicking a feature for the first time stores the filtered map state in some type of cache and it keeps reloading it whenever I try to interact with another filtered map.

So my question is: is there a proper way to do this? Ideally I'd like my custom filter widget to communicate with the native Filter Widget to create filters but I'm new to custom widgets and can't find any information on how to do that. Thank you for your help.

TristanJonas_0-1754318329461.png



// Applies filter to BOTH DataSource and Visual Layer for persistence + immediate feedback
export const applyPersistentFilter = async (
    layerInfo: LayerInfo,
    filter: string,
    widgetId: string
): Promise<boolean> => {
    try {
        // Step 1: Apply through Experience Builder's DataSource system (for persistence)
        const dataSourceSuccess = await applyFilterThroughDataSource(layerInfo, filter, widgetId)

        // Step 2: Apply to visual layer (for immediate map update)
        const visualSuccess = applyFilterToVisualLayer(layerInfo, filter)

        return dataSourceSuccess && visualSuccess
    } catch (error) {
        console.error('Error applying persistent filter:', error)
        return false
    }
}

// DataSource persistence method
const applyFilterThroughDataSource = async (layerInfo: LayerInfo, filter: string, widgetId: string): Promise<boolean> => {
    const dsManager = DataSourceManager.getInstance()
    const allDataSources = dsManager.getDataSources()

    // Find WEB_MAP DataSource
    let webMapDataSource: DataSource | null = null
    for (const [dsId, dataSource] of Object.entries(allDataSources)) {
        const dsJson = dataSource.getDataSourceJson()
        if (dsJson.type === 'WEB_MAP') {
            webMapDataSource = dataSource
            break
        }
    }

    if (webMapDataSource) {
        const webMapDs = webMapDataSource as any
        // Find target layer in DataSource map
        webMapDs.map.allLayers.forEach((layer: any) => {
            if (layer.id === layerInfo.id) {
                layer.definitionExpression = filter
            }
        })
        
        // Publish filter message to notify other widgets
        MessageManager.getInstance().publishMessage(
            new DataSourceFilterChangeMessage(widgetId, [webMapDataSource.id])
        )
    }
}

// Visual layer immediate update
const applyFilterToVisualLayer = (layerInfo: LayerInfo, filter: string): boolean => {
    layerInfo.lyr.definitionExpression = filter
    return true
}

 

0 Kudos
1 Solution

Accepted Solutions
TristanJonas
Occasional Contributor

Pretty sure I figured it out, so I was directly updating the definitionExpression with the filter, however the PROPER approach is through these channels:

// Use Experience Builder's proper data source system
const jimuLayerViews = jmv.getAllJimuLayerViews()
const targetLayerView = jimuLayerViews.find(view => view.layer.id === layerInfo.id)
const dataSource = await targetLayerView.createLayerDataSource()
dataSource.updateQueryParams({ where: filter }, widgetId)

 
This is the proper approach and I identified it by looking through here:

https://community.esri.com/t5/arcgis-experience-builder-questions/layer-filter-is-removed-when-popup...

View solution in original post

3 Replies
VenkataKondepati
Emerging Contributor

Hi @TristanJonas,

You're encountering a common Experience Builder behavior: by default, clicking on a map feature often triggers a record selection change, which can unintentionally reset or overwrite filters if widgets are wired incorrectly.

Open your Filter widget and ensure "Apply this filter automatically" is off if you want manual control, or that the filter is scoped as desired (e.g., default vs selection data view). If inside a Widget Controller, note that filters don’t activate until the panel opens

Then configure Message Actions on your Map widget: add a "Record selection changes" trigger with a “Filter data records” action targeting only the list or map widgets you intend and do not connect it to the filter widget unless needed focus is intended.

Double-check that Filter widget isn’t also reset by another trigger like Map extent or selection changes you didn’t intend.

In short: your filter is resetting because a map-triggered action is affecting it. Use selective message-trigger configuration so click events only filter the target widget(s) and leave your active filters intact.

I hope this helps and let me know.

Regards,

Venkat




0 Kudos
TristanJonas
Occasional Contributor

Hi Venkat, thank you for your quick reply. I'd like to address your points:

1. As of now the only native filter I have in my Web Experience Builder is the one built into the Layer Selection so there is no "Apply this filter automatically" to consider in my case.

2. For testing purposes I've eliminated all elements besides the Map, the Layer List, and the Custom Filter Widget, but I don't have the option to set my Custom Filter Widget as an action item connected to the Map:

TristanJonas_1-1754324227316.png

 

TristanJonas_0-1754324174979.png

3. As far as I can tell, all possible settings that would trigger anything at all have been disabled, I don't think there's any triggerable actions within the Experience Builder anymore but this behavior persists.

I attached the widget itself if anyone wants to look at it, I think the code I posted above is sufficient but maybe something else in the widget is causing this issue.

Thank you again for your help

Edit: After solving I removed proprietary widget.

0 Kudos
TristanJonas
Occasional Contributor

Pretty sure I figured it out, so I was directly updating the definitionExpression with the filter, however the PROPER approach is through these channels:

// Use Experience Builder's proper data source system
const jimuLayerViews = jmv.getAllJimuLayerViews()
const targetLayerView = jimuLayerViews.find(view => view.layer.id === layerInfo.id)
const dataSource = await targetLayerView.createLayerDataSource()
dataSource.updateQueryParams({ where: filter }, widgetId)

 
This is the proper approach and I identified it by looking through here:

https://community.esri.com/t5/arcgis-experience-builder-questions/layer-filter-is-removed-when-popup...