Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Baha Al Fataftah 4 posts 75 karma points
    Nov 11, 2018 @ 20:24
    Baha Al Fataftah
    0

    Reset Filters When revisiting a view in Umbraco custom Section

    Hi I'm using custom sections in Umbraco for a while now, and I noticed that filters still there when I revisit a dashboard I've filtered its data before.

    Scenario:

    1. Visit custom section dashboard view
    2. Filter data using any of the filters
    3. navigate to any default/custom sections
    4. navigate back to the custom section you visited in step 1
    5. after biding the data the filters get its selected state back

    Note that I create dashboard view the same way used in Users default section.

    <div style="position: relative;" ng-if="vm.CountryFilter.length > 0">
                <a class="btn btn-link dropdown-toggle flex" href="" ng-click="vm.toggleFilter('country')">
                    <span><localize key="usersmanager_Country">Country</localize>:</span>
                    <span class="bold truncate dib" style="margin-left: 5px; margin-right: 3px; max-width: 250px;">{{ vm.getFilterName(vm.CountryFilter) }}</span>
                    <span class="caret"></span>
                </a>
                <umb-dropdown class="pull-right" ng-if="vm.page.showCountryFilter" on-close="vm.page.showCountryFilter = false;">
                    <umb-dropdown-item ng-repeat="o in vm.CountryFilter | filter:{ count: '!0', key: '!All'} : true" style="padding: 8px 20px 8px 16px;">
                        <div class="flex items-center">
                            <input id="country-{{$index}}"
                                   type="checkbox"
                                   ng-model="o.selected"
                                   ng-change="vm.setCountryFilter(o)"
                                   style="margin-right: 10px; margin-top: -3px;" no-dirty-check />
                            <label for="state-{{$index}}">{{ o.name }} ({{o.count}})</label>
                        </div>
                    </umb-dropdown-item>
                </umb-dropdown>
            </div>
    

    This should return All as when you first visit the page:

    vm.getFilterName(vm.CountryFilter)
    

    body of function is:

    function getFilterName(array) {
            var name = "All";
            var found = false;
            angular.forEach(array, function (item) {
                if (item.selected) {
                    if (!found) {
                        name = item.name
                        found = true;
                    } else {
                        name = name + ", " + item.name;
                    }
                }
            });
            return name;
        }
    

    enter image description here

    The filter state should be reset when I revisit a view as the data is not filtered when the page loads.

Please Sign in or register to post replies

Write your reply to:

Draft