Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show dropdown values with count using Angularjs Dropdown Multiselect?

AngularJS Dropdown Multiselect -- Search Custom template per option.

I have found the solution of my query will be using the above url of the documentation of AngularJS Dropdown Multiselect but if I am using the below code, it doesn't reflect on the view of my application:

$scope.example19settings = {
    template: '<b>{{option.name}}</b>'
};

I want to acheive it by adding a count:

$scope.example19settings = {
    template: '<b>{{option.name}}({{option.count}})</b>'
};

Any suggestions or missing links?

$scope.extraSettings = {
    settings: {
        selectedToTop: true,
        styleActive: true,
        /*template: '<b>{{option.label}}</b>'*/
        scrollable: true,
        scrollableHeight: 200,
        showEnableSearchButton: true        
    }
};
like image 225
GOK Avatar asked Nov 13 '17 08:11

GOK


2 Answers

Please find working solution below. Following are the changes I have done.

  1. Change the reference if miltiselect library to this (latest)

  2. Added the 'angularjs-dropdown-multiselect' as dependency to my main app module

  3. Created a controller MainCtrl, assigned it to the template
  4. Added an extra property ($scope.example19model = [];) to $scope for holding selected options.

Let me know, if this works for you :)

var app = angular.module('app', ['angularjs-dropdown-multiselect']);

app.controller('MainCtrl', function($scope) {
  $scope.example19model = [];
  $scope.example19data = [{
    id: 1,
    name: "David",
    count: 20
  }, {
    id: 2,
    name: "Jhon",
    count: 30
  }, {
    id: 3,
    name: "Lisa",
    count: 40
  }, {
    id: 4,
    name: "Nicole",
    count: 50
  }, {
    id: 5,
    name: "Danny",
    count: 60
  }];

  $scope.example19settings = {
    template: '<b>{{option.name}} ({{option.count}})</b>'
  };
})
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.5/angular.js"></script>
<script src="https://rawgit.com/dotansimha/angularjs-dropdown-multiselect/master/dist/angularjs-dropdown-multiselect.min.js"></script>

<div ng-app="app">
  <div ng-controller="MainCtrl">
    <div ng-dropdown-multiselect="" options="example19data" selected-model="example19model" extra-settings="example19settings"></div>
    {{example19model}}
  </div>
</div>
like image 107
Vipin Kumar Avatar answered Oct 20 '22 00:10

Vipin Kumar


You can use select2 library which helps to select multiple inputs.

Check this link for live demo.

<h3>Array of strings</h3> <ui-select multiple ng-model="ctrl.multipleDemo.colors" theme="bootstrap" ng-disabled="ctrl.disabled" close-on-select="false" style="width: 300px;" title="Choose a color"> <ui-select-match placeholder="Select colors...">{{$item}}</ui-select-match> <ui-select-choices repeat="color in ctrl.availableColors | filter:$select.search"> {{color}} </ui-select-choices> </ui-select> <p>Selected: {{ctrl.multipleDemo.colors}}</p>

like image 22
nitheeshsalian Avatar answered Oct 20 '22 02:10

nitheeshsalian