ui-select icon indicating copy to clipboard operation
ui-select copied to clipboard

Adding spinner or searching

Open bardam opened this issue 12 years ago • 10 comments

Is there on option to display a spinner or "Searching..." text till the refresh method finished? I'm loading the data remotely and it can take 2-3 seconds till I get the data.

bardam avatar Oct 28 '14 12:10 bardam

I guess you have to handle this by yourself. I also load the data via ajax (ok takes only 400 to 800 ms) but i also want to show the spinner as indicator for the user that something is happen.

markusguenther avatar Nov 18 '14 14:11 markusguenther

Maybe not the best coding style but i am new in angular.

Example:

<div class="input-group">
            <div ng-show="loadUsers" class="loading-indicator"></div>
            <ui-select ng-model="userDefault.selected" theme="bootstrap">
                <ui-select-match placeholder="{f:translate(key: 'backend.recordlog.filter.placeholder.users')}">{{$select.selected.name}}</ui-select-match>
                <ui-select-choices refresh="fetchUsers($select.search)" refresh-delay="300" repeat="user in users | orderBy:'name' | filter:$select.search">
                    <div ng-bind-html="user.name | highlight: $select.search"></div>
                    <small ng-bind-html="user.email | highlight: $select.search"></small>
                </ui-select-choices>
            </ui-select>

            <span class="input-group-btn">
                <button ng-click="resetToDefault()" class="btn btn-default">
                    <span class="glyphicon glyphicon-remove"></span>
                </button>
            </span>
        </div>

And the related javascript code used in my directive:

function fetchUsersBySearchTerm(searchTerm) {
                        var parameters = {'searchTerm': searchTerm};
                        $scope.loadUsers = true;

                        AjaxService.users(parameters).then(
                            function(payload) {
                                var users = payload.data;
                                UserService.setUsers(users);
                                $scope.users = convertObjectToArray(users);
                                $scope.loadUsers = false;
                            }
                        );
                    }

markusguenther avatar Nov 18 '14 16:11 markusguenther

@markusguenther Tip: if your AjaxService is using ngResource you should definitely look at the $resolved property of the return value

wald-tq avatar Nov 20 '14 12:11 wald-tq

Actually i only use $http. But i have heard of ngRessource and will try it anytime :) Thanks for the hint.

markusguenther avatar Nov 20 '14 14:11 markusguenther

I need this functionality as well. I need it to go one step further as well. I'm using a remote data source to ajax in search results. I need a way to display what amounts to a "no records found" message when the search returns no results.

---Update--- I "solved" this by extending the uiSelectChoices directive.

MikeABentley avatar Feb 19 '15 15:02 MikeABentley

@MBentley1976 can you provide an example? Thinking this should be included in base.

amcdnl avatar Apr 06 '15 15:04 amcdnl

Any updates?

seinavco avatar Apr 12 '15 14:04 seinavco

Heres my solution....

/**
     * Get Data products...will be Injected into products
     */
    $scope.products = [];
    $scope.isProductFound  = false;
    $scope.getProducts = function(search) {

        if(!search) return;

        $scope.isProductLoaded = true; //for loading info when a search for product is conducted        
        var params = {search: search, warehouse_id : $scope.warehouse.selectedWarehouseId};

        return $http.get(SITE_URL + 'transaction/getProducts', {params: params} ).then(function(response) {

            $scope.products = response.data.data
            if (response.data.data.length < 1) {

                $scope.isProductFound  = true;
            } else {

                $scope.isProductFound  = false;
            }

            $scope.isProductLoaded = false;
        });
    };
<div class="input-group">
 <ui-select name="product" ng-model="product.no_int_product" on-select=onSelectProduct($item) theme="bootstrap" reset-search-input="true" style="width:500px">
    <ui-select-match placeholder="Search product by Name, Code..">{{$select.selected.product_name}}</ui-select-match>
    <ui-select-choices repeat="product.no_int_product as product in products"
                   refresh="getProducts($select.search)"
                    refresh-delay="500" style="width:500px">
      <div ng-bind-html="product.product_name"></div>
      </ui-select-choices>
</ui-select>
<!-- Show only when loading... -->
<span class="input-group-addon" ng-show="isProductLoaded && !isProductFound" style="background: none;border:none"><i class="fa fa-spinner fa-pulse"></i></span>
<!-- Show only If product not found -->
<span class="input-group-addon" style="background: none;border:none" ng-show="isProductFound">Not found...</span>
</div>

teknosains avatar Nov 13 '15 17:11 teknosains

FWIW I think this is now here: https://github.com/angular-ui/ui-select/pull/1779

simonv3 avatar Oct 27 '16 16:10 simonv3

Closing as resolved by #1779

user378230 avatar Nov 21 '16 20:11 user378230