isteven / angular-multi-select

A multi select dropdown directive for AngularJS. Allows you to use HTML tags and CSS in the data. Requires only AngularJS and nothing else.
isteven.github.io/angular-multi-select
MIT License
1.08k stars 518 forks source link

Add functionallity to accept groups without childs. #269

Open danicomas opened 9 years ago

danicomas commented 9 years ago

The following should work:

var u = [
    {
      name: "<strong>All Browsers</strong>",
      msGroup: true
    },
    {
      name: "<strong>Europe</strong>",
      msGroup: true,
    },
    {
      msGroup: false
    },
    {
      name: "<strong>Asia & Pacific</strong>",
      msGroup: true
    },
    {
      msGroup: false
    },
    {
      name: "<strong>Middle East</strong>",
      msGroup: true
    },
    {
      msGroup: false
    },
    {
      msGroup: false
    }];

Now only load if I have childs!

var u = [
    {
      name: "<strong>All Browsers</strong>",
      msGroup: true
    },
    {
      name: "<strong>Europe</strong>",
      msGroup: true,
    },
    { 
       icon: '<img  src="https://cdn1.iconfinder.com/data/icons/fatcow/32/opera.png" />',                         
       name: 'Only loads this hierarchy',              
       maker: 'Only loads this hierarchy',        
        ticked: false
     },
    {
      msGroup: false
    },
    {
      name: "<strong>Asia & Pacific</strong>",
      msGroup: true
    },
    {
      msGroup: false
    },
    {
      name: "<strong>Middle East</strong>",
      msGroup: true
    },
    {
      msGroup: false
    },
    {
      msGroup: false
    }];
isteven commented 9 years ago

Hi @danicomas ,

Sorry for the late reply.

Actually this is not a bug, I intentionally made it to remove empty groups. But I guess you're right, it should be able to display empty groups. Will update on the next release.

danicomas commented 9 years ago

Nice @isteven

elyrank commented 7 years ago

Hi @isteven what is the status of this issue? would it be possible to select the group head to select all its members including the header?

cschwaderer commented 4 years ago

For those still interested: The crucial code block in isteven-angular-multiselect/isteven-multi-select.js seems to be

if (
     (
         !$scope.filteredModel[ $scope.filteredModel.length - 1 ]
         ||
         typeof $scope.filteredModel[ $scope.filteredModel.length - 1 ][ attrs.groupProperty ] !== 'undefined'
       )
       &&
       (
         !$scope.filteredModel[ $scope.filteredModel.length - 1 ]
         ||
         $scope.filteredModel[ $scope.filteredModel.length - 1 ][ attrs.groupProperty ] === false
       )
) {
  $scope.filteredModel.pop();
}
else {
  $scope.filteredModel.push( $scope.inputModel[ i ] );
    }

You might want to change it so that $scope.filteredModel.push( $scope.inputModel[ i ] ); is either always called or based on an attribute condition.