Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,21 @@ export class AppComponent implements OnInit {
dropdownSettings = {};
ngOnInit() {
this.dropdownList = [
{ item_id: 1, item_text: 'Mumbai' },
{ item_id: 2, item_text: 'Bangaluru' },
{ item_id: 3, item_text: 'Pune' },
{ item_id: 1, item_text: 'Mumbai', item_icon: 'fa fa-home' },
{ item_id: 2, item_text: 'Bangaluru', item_icon: 'fa fa-truck' },
{ item_id: 3, item_text: 'Pune', item_icon: 'fa fa-wifi' },
{ item_id: 4, item_text: 'Navsari' },
{ item_id: 5, item_text: 'New Delhi' }
];
this.selectedItems = [
{ item_id: 3, item_text: 'Pune' },
{ item_id: 3, item_text: 'Pune', item_icon: 'fa fa-wifi' },
{ item_id: 4, item_text: 'Navsari' }
];
this.dropdownSettings:IDropdownSettings = {
singleSelection: false,
idField: 'item_id',
textField: 'item_text',
iconField: 'item_icon',
selectAllText: 'Select All',
unSelectAllText: 'UnSelect All',
itemsShowLimit: 3,
Expand Down Expand Up @@ -108,6 +109,7 @@ export class AppComponent implements OnInit {
| data | Array<any> | Array of items from which to select. Should be an array of objects with id and `text` properties. You can also use custom properties. In that case you need to map idField and `textField` properties. As convenience, you may also pass an array of strings, in which case the same string is used for both the ID and the text(no mapping is required) | n/a |
| idField | String | map id field in case of custom array of object | 'id' |
| textField | String | map text field in case of custom array of object | 'text' |
| iconField | String | map icon field in case of custom array of object | 'icon' |
| enableCheckAll | Boolean | Enable the option to select all items in list | false |
| selectAllText | String | Text to display as the label of select all option | Select All |
| unSelectAllText | String | Text to display as the label of unSelect option | UnSelect All |
Expand Down Expand Up @@ -183,6 +185,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<td align="center"><a href="http://sacgro.com"><img src="https://avatars1.githubusercontent.com/u/1292182?v=4" width="100px;" alt=""/><br /><sub><b>Sachin Grover</b></sub></a><br /><a href="https://github.com/Nilesh Patel/ng-multiselect-dropdown/commits?author=sacgrover" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/WWL-MikeRoberts"><img src="https://avatars3.githubusercontent.com/u/9750056?v=4" width="100px;" alt=""/><br /><sub><b>Mike Roberts</b></sub></a><br /><a href="https://github.com/Nilesh Patel/ng-multiselect-dropdown/commits?author=WWL-MikeRoberts" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/DsosaV"><img src="https://avatars2.githubusercontent.com/u/3926475?v=4" width="100px;" alt=""/><br /><sub><b>David Sosa</b></sub></a><br /><a href="https://github.com/Nilesh Patel/ng-multiselect-dropdown/commits?author=DsosaV" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/victor-valencia"><img src="https://avatars1.githubusercontent.com/u/3579937?s=460&u=7135c485e2ff1b62fd195e5ebe38a6ccf03799ef&v=4" width="100px;" alt=""/><br /><sub><b>Victor Valencia</b></sub></a><br /><a href="https://github.com/Nilesh Patel/ng-multiselect-dropdown/commits?author=victor-valencia" title="Code">💻</a></td>
</tr>
</table>

Expand Down
3 changes: 2 additions & 1 deletion angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"src/favicon.ico"
],
"styles": [
"src/styles.scss"
"src/styles.scss",
"src/app/assets/vendor/font-awesome-4.7.0/css/font-awesome.min.css"
],
"scripts": []
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ng-multiselect-dropdown",
"version": "0.2.10",
"version": "0.2.11",
"private": true,
"description": "Angular Multi-Select Dropdown",
"author": "Nilesh Patel",
Expand Down
35 changes: 20 additions & 15 deletions src/app/components/select/multiple-demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,22 @@ export class MultipleDemoComponent implements OnInit {

ngOnInit() {
this.cities = [
{ item_id: 1, item_text: 'New Delhi' },
{ item_id: 2, item_text: 'Mumbai' },
{ item_id: 3, item_text: 'Bangalore' },
{ item_id: 4, item_text: 'Pune' },
{ item_id: 5, item_text: 'Chennai' },
{ item_id: 6, item_text: 'Navsari' }
{ item_id: 1, item_text: 'New Delhi', item_icon: 'fa fa-home' },
{ item_id: 2, item_text: 'Mumbai', item_icon: 'fa fa-floppy-o' },
{ item_id: 3, item_text: 'Bangalore', item_icon: 'fa fa-trash' },
{ item_id: 4, item_text: 'Pune', item_icon: 'fa fa-truck' },
{ item_id: 5, item_text: 'Chennai', item_icon: 'fa fa-video-camera' },
{ item_id: 6, item_text: 'Navsari', item_icon: 'fa fa-wifi' }
];
this.selectedItems = [
{ item_id: 4, item_text: 'Pune', item_icon: 'fa fa-truck' },
{ item_id: 6, item_text: 'Navsari', item_icon: 'fa fa-wifi' }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The existing code should be unbothered. This would need to be refactored to not touch existing code.

];
this.selectedItems = [{ item_id: 4, item_text: 'Pune' }, { item_id: 6, item_text: 'Navsari' }];
this.dropdownSettings = {
singleSelection: false,
idField: 'item_id',
textField: 'item_text',
iconField: 'item_icon',
selectAllText: 'Select All',
unSelectAllText: 'UnSelect All',
itemsShowLimit: 3,
Expand Down Expand Up @@ -96,22 +100,23 @@ export class MultipleDemoComponent implements OnInit {

ngOnInit() {
this.cities = [
{ item_id: 1, item_text: 'New Delhi' },
{ item_id: 2, item_text: 'Mumbai' },
{ item_id: 3, item_text: 'Bangalore', isDisabled: this.disableBangalore },
{ item_id: 4, item_text: 'Pune' },
{ item_id: 5, item_text: 'Chennai' },
{ item_id: 6, item_text: 'Navsari' }
{ item_id: 1, item_text: 'New Delhi', item_icon: 'fa fa-home' },
{ item_id: 2, item_text: 'Mumbai', item_icon: 'fa fa-floppy-o' },
{ item_id: 3, item_text: 'Bangalore', isDisabled: this.disableBangalore, item_icon: 'fa fa-trash' },
{ item_id: 4, item_text: 'Pune', item_icon: 'fa fa-truck' },
{ item_id: 5, item_text: 'Chennai', item_icon: 'fa fa-video-camera' },
{ item_id: 6, item_text: 'Navsari', item_icon: 'fa fa-wifi' }
];
this.selectedItems = [
{ item_id: 4, item_text: 'Pune' },
{ item_id: 6, item_text: 'Navsari' }
{ item_id: 4, item_text: 'Pune', item_icon: 'fa fa-truck' },
{ item_id: 6, item_text: 'Navsari', item_icon: 'fa fa-wifi' }
];
this.dropdownSettings = {
singleSelection: false,
defaultOpen: false,
idField: 'item_id',
textField: 'item_text',
iconField: 'item_icon',
selectAllText: 'Select All',
unSelectAllText: 'UnSelect All',
enableCheckAll: this.showAll,
Expand Down
4 changes: 2 additions & 2 deletions src/ng-multiselect-dropdown/src/multi-select.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<span tabindex="-1" class="dropdown-btn" (click)="toggleDropdown($event)">
<span *ngIf="selectedItems.length == 0">{{_placeholder}}</span>
<span class="selected-item" *ngFor="let item of selectedItems;trackBy: trackByFn;let k = index" [hidden]="k > _settings.itemsShowLimit-1">
{{item.text}}
<i class="{{item.icon}}"></i> {{item.text}}
<a style="padding-top:2px;padding-left:2px;color:white" (click)="onItemClick($event,item)">x</a>
</span>
<span style="float:right !important;padding-right:4px">
Expand All @@ -25,7 +25,7 @@
<ul class="item2" [style.maxHeight]="_settings.maxHeight+'px'">
<li *ngFor="let item of _data | multiSelectFilter:filter; let i = index;" (click)="onItemClick($event,item)" class="multiselect-item-checkbox">
<input type="checkbox" aria-label="multiselect-item" [checked]="isSelected(item)" [disabled]="disabled || (isLimitSelectionReached() && !isSelected(item)) || item.isDisabled" />
<div>{{item.text}}</div>
<div><i class="{{item.icon}}"></i> {{item.text}}</div>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anything related to icons would need to be tested first. You have modified the code as if 100% of users would consume this property. It would be an optional property.
<i *ngIf="item?.icon" class="{{item.icon}}">

</li>
<li class='no-data' *ngIf="_data.length == 0 && !_settings.allowRemoteDataSearch">
<h5>{{_settings.noDataAvailablePlaceholderText}}</h5>
Expand Down
5 changes: 5 additions & 0 deletions src/ng-multiselect-dropdown/src/multiselect.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export class MultiSelectComponent implements ControlValueAccessor {
singleSelection: false,
idField: "id",
textField: "text",
iconField: "icon",
disabledField: "isDisabled",
enableCheckAll: true,
selectAllText: "Select All",
Expand Down Expand Up @@ -81,6 +82,7 @@ export class MultiSelectComponent implements ControlValueAccessor {
: new ListItem({
id: item[this._settings.idField],
text: item[this._settings.textField],
icon: item[this._settings.iconField],
isDisabled: item[this._settings.disabledField]
})
);
Expand Down Expand Up @@ -144,6 +146,7 @@ export class MultiSelectComponent implements ControlValueAccessor {
: new ListItem({
id: firstItem[this._settings.idField],
text: firstItem[this._settings.textField],
icon: firstItem[this._settings.iconField],
isDisabled: firstItem[this._settings.disabledField]
})
];
Expand All @@ -158,6 +161,7 @@ export class MultiSelectComponent implements ControlValueAccessor {
: new ListItem({
id: item[this._settings.idField],
text: item[this._settings.textField],
icon: item[this._settings.iconField],
isDisabled: item[this._settings.disabledField]
})
);
Expand Down Expand Up @@ -276,6 +280,7 @@ export class MultiSelectComponent implements ControlValueAccessor {
const obj = {};
obj[this._settings.idField] = val.id;
obj[this._settings.textField] = val.text;
obj[this._settings.iconField] = val.icon;
if (this._sourceDataFields.includes(this._settings.disabledField)) {
obj[this._settings.disabledField] = val.isDisabled;
}
Expand Down
4 changes: 4 additions & 0 deletions src/ng-multiselect-dropdown/src/multiselect.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export interface IDropdownSettings {
singleSelection?: boolean;
idField?: string;
textField?: string;
iconField?: string;
disabledField?: string;
enableCheckAll?: boolean;
selectAllText?: string;
Expand All @@ -22,16 +23,19 @@ export interface IDropdownSettings {
export class ListItem {
id: String | number;
text: String | number;
icon: String;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would need to be an optional parameter as not everyone would use an icon.

isDisabled?: boolean;

public constructor(source: any) {
if (typeof source === 'string' || typeof source === 'number') {
this.id = this.text = source;
this.icon = '';
this.isDisabled = false;
}
if (typeof source === 'object') {
this.id = source.id;
this.text = source.text;
this.icon = source.icon;
this.isDisabled = source.isDisabled;
}
}
Expand Down