DevExtreme Angular - Selection

API

The selection capability is not provided out of the box, but it can be implemented using the onItemClick event handler. The following code gives an example for the scenario when a click on a funnel item selects it, and a subsequent click on the same item clears the selection. To check whether the funnel item is already selected, its isSelected() method is called.

jQuery
JavaScript
$(function() {
    $("#funnelContainer").dxFunnel({
        // ...
        onItemClick: function (e) {
            e.item.select(!e.item.isSelected())
        }
    });
});
Angular
HTML
TypeScript
<dx-funnel
    (onItemClick)="onItemClick($event)">
</dx-funnel>
import { DxFunnelModule } from "devextreme-angular";
// ...
export class AppComponent {
    onItemClick (e) {
        e.item.select(!e.item.isSelected())
    };
}
@NgModule({
    imports: [
        // ...
        DxFunnelModule
    ],
    // ...
})
Vue
App.vue
<template> 
    <DxFunnel
        @item-click="onItemClick"
    />
</template>

<script>
import DxFunnel from 'devextreme-vue/funnel';

export default {
    components: {
        DxFunnel
    },
    methods: {
        onItemClick (e) {
           e.item.select(!e.item.isSelected())
        }
    }
}
</script>
React
App.js
import React from 'react';
import Funnel from 'devextreme-react/funnel';

class App extends React.Component {
    render() {
        return (
            <Funnel
                onItemClick={onItemClick}
            />
        );
    }
}

function onItemClick (e) {
    e.item.select(!e.item.isSelected())
}

export default App;

In the previous code example, selection was cleared of a specific item. If you need to clear selection of all items, call the Funnel's clearSelection() method.

jQuery
JavaScript
$("#funnelContainer").dxFunnel("clearSelection");
Angular
TypeScript
import { ..., ViewChild } from "@angular/core";
import { DxFunnelModule, DxFunnelComponent } from "devextreme-angular";
// ...
export class AppComponent {
    @ViewChild(DxFunnelComponent, { static: false }) funnel: DxFunnelComponent;
    // Prior to Angular 8
    // @ViewChild(DxFunnelComponent) funnel: DxFunnelComponent;
    clearSelection() {
        this.funnel.instance.clearSelection();
    }
}
@NgModule({
    imports: [
        // ...
        DxFunnelModule
    ],
    // ...
})
Vue
App.vue
<template> 
    <DxFunnel ref="funnel" />
</template>

<script>
import DxFunnel from 'devextreme-vue/funnel';

export default {
    components: {
        DxFunnel
    },
    methods: {
        clearSelection () {
            return this.$refs.funnel.instance.clearSelection();
        }
    }
}
</script>
React
App.js
import React from 'react';
import Funnel from 'devextreme-react/funnel';

class App extends React.Component {
    constructor(props) {
        super(props);
        this.funnelRef = React.createRef();
    }
    render() {
        return (
            <Funnel ref={this.funnelRef} />
        );
    }
    get funnel() {
        return this.funnelRef.current.instance;
    }
    clearSelection () {
        return this.funnel.clearSelection();
    }
}

export default App;
See Also

User Interaction

When a user selects funnel items, they change their style to the one specified by the item.selectionStyle object.

jQuery
JavaScript
$(function() {
    $("#funnelContainer").dxFunnel({
        // ...
        item: {
            selectionStyle: {
                hatching: { direction: "left" }
            }
        }
    });
});
Angular
HTML
TypeScript
<dx-funnel ... >
    <dxo-item>
        <dxo-selection-style>
            <dxo-hatching direction="left"></dxo-hatching>
        </dxo-selection-style>
    </dxo-item>
</dx-funnel>
import { DxFunnelModule } from "devextreme-angular";
// ...
export class AppComponent {
    // ...
}
@NgModule({
    imports: [
        // ...
        DxFunnelModule
    ],
    // ...
})
Vue
App.vue
<template> 
    <DxFunnel ... >
        <DxItem ... >
            <DxSelectionStyle>
                <DxHatching direction="left" />
            </DxSelectionStyle>
        </DxItem>
    </DxFunnel>
</template>

<script>
import DxFunnel, {
    DxItem,
    DxSelectionStyle,
    DxHatching
} from 'devextreme-vue/funnel';

export default {
    components: {
        DxFunnel,
        DxItem,
        DxSelectionStyle,
        DxHatching
    }
}
</script>
React
App.js
import React from 'react';
import Funnel, {
    Item,
    SelectionStyle,
    Hatching
} from 'devextreme-react/funnel';

class App extends React.Component {
    render() {
        return (
            <Funnel ... >
                <Item ... >
                    <SelectionStyle>
                        <Hatching direction="left" />
                    </SelectionStyle>
                </Item>
            </Funnel>
        );
    }
}

export default App;

Events

When a funnel item's selection state is being changed, the Funnel raises the selectionChanged event that you can handle with a function. If the handling function is not going to be changed during the lifetime of the widget, assign it to the onSelectionChanged option when you configure the widget. To check whether a funnel item was selected or the selection was cleared, call the item's isSelected() method.

jQuery
JavaScript
$(function() {
    $("#funnelContainer").dxFunnel({
        // ...
        onSelectionChanged: function (e) {
            if (e.item.isSelected()) {
                // Commands to execute when the item is selected
            } else {
                // Commands to execute when the selection is cleared
            }
        }
    });
});
Angular
HTML
JavaScript
<dx-funnel ...
    (onSelectionChanged)="onSelectionChanged($event)">
</dx-funnel>
import { DxFunnelModule } from "devextreme-angular";
// ...
export class AppComponent {
    onSelectionChanged (e) {
        if (e.item.isSelected()) {
            // Commands to execute when the item is selected
        } else {
            // Commands to execute when the selection is cleared
        }
    };
}
@NgModule({
    imports: [
        // ...
        DxFunnelModule
    ],
    // ...
})
Vue
App.vue
<template> 
    <DxFunnel
        @selection-changed="onSelectionChanged"
    />
</template>

<script>
import DxFunnel from 'devextreme-vue/funnel';

export default {
    components: {
        DxFunnel
    },
    methods: {
        onSelectionChanged (e) {
            if (e.item.isSelected()) {
                // Commands to execute when the item is selected
            } else {
                // Commands to execute when the selection is cleared
            }
        }
    }
}
</script>
React
App.js
import React from 'react';
import Funnel from 'devextreme-react/funnel';

class App extends React.Component {
    render() {
        return (
            <Funnel
                onSelectionChanged={onSelectionChanged}
            />
        );
    }
}

function onSelectionChanged (e) {
    if (e.item.isSelected()) {
        // Commands to execute when the item is selected
    } else {
        // Commands to execute when the selection is cleared
    }
}

export default App;

If you are going to change the event handler at runtime, or if you need to attach several handlers to the selectionChanged event, subscribe to this event using the on(eventName, eventHandler) method. This approach is more typical of jQuery.

JavaScript
var selectionChangedHandler1 = function (e) {
    // First handler of the "selectionChanged" event
};

var selectionChangedHandler2 = function (e) {
    // Second handler of the "selectionChanged" event
};

$("#funnelContainer").dxFunnel("instance")
    .on("selectionChanged", selectionChangedHandler1)
    .on("selectionChanged", selectionChangedHandler2);
See Also