Skip to content

Commit da307cc

Browse files
author
Pradeep Terli
committed
bug fixes and add new item if not found on filter feature.
1 parent f74a11b commit da307cc

File tree

13 files changed

+148
-13
lines changed

13 files changed

+148
-13
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,8 @@ The following list of settings are supported by the component. Configure the set
248248
| searchBy | Array | Search the list by certain properties of the list item. Ex: ["itemName, "id","name"]. Deafult is , it will search the list by all the properties of list item | [] |
249249
| lazyLoading | Boolean | Enable lazy loading. Used to render large datasets. | false |
250250
| showCheckbox | Boolean | Show or hide checkboxes in the list | true |
251-
251+
| addNewItemOnFilter | Boolean | Whe you filter items and if, the item is not found, you can add the text as new item to the list | false |
252+
| addNewButtonText | String | The text in the button when `addNewItemOnFilter` is enabled | 'Add' |
252253

253254
### Events
254255
- `onSelect` - Return the selected item on selection.
@@ -265,6 +266,8 @@ The following list of settings are supported by the component. Configure the set
265266
Example : (onClose)="onClose($event)"
266267
- `onScrollToEnd` - Callback event fired when the dropdown list is scrolled to the end. Usually used with virtual scrolling, to load data on scroll.
267268
Example : (onScrollToEnd)="fetchMore($event)"
269+
- `onAddFilterNewItem` - Callback event fired when you click the `Add` button which will appear when `addNewItemOnFilter` setting is enabled.
270+
Example : (onAddFilterNewItem)="onAddItem($event)"
268271

269272
## Run locally
270273
- Clone the repository or downlod the .zip,.tar files.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular2-multiselect-dropdown",
3-
"version": "4.0.0",
3+
"version": "4.1.0",
44
"description": "Angular 2 and angular 4 multiselect dropdown component.",
55
"keywords": [
66
"angular 2 multiselect dropdown",

projects/angular2-multiselect-dropdown-lib/src/lib/multiselect.component.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,10 @@
8383
<span [hidden]="!isFilterSelectAll">{{settings.filterUnSelectAllText}}</span>
8484
</label>
8585
</div>
86-
<label *ngIf="filterLength == 0" [hidden]="filter == undefined || filter?.length == 0">{{settings.noDataLabel}}</label>
86+
<label class="nodata-label" *ngIf="filterLength == 0" [hidden]="filter == undefined || filter?.length == 0">{{settings.noDataLabel}}</label>
87+
<div class="btn-container" *ngIf="settings.addNewItemOnFilter && filterLength == 0" [hidden]="filter == undefined || filter?.length == 0">
88+
<button class="c-btn btn-iceblue" (click)="addFilterNewItem()">{{settings.addNewButtonText}}</button>
89+
</div>
8790
</div>
8891
<div class="filter-select-all" *ngIf="settings.lazyLoading && settings.enableFilterSelectAll">
8992
<div class="pure-checkbox select-all" *ngIf="filter?.length > 0 && infiniteFilterLength > 0" (click)="toggleInfiniteFilterSelectAll()">
@@ -113,7 +116,7 @@
113116
class="pure-checkbox" [ngClass]="{'selected-item': isSelected(item) == true }">
114117
<input *ngIf="settings.showCheckbox" type="checkbox" [checked]="isSelected(item)" [disabled]="settings.limitSelection == selectedItems?.length && !isSelected(item)"
115118
/>
116-
<label>{{item.id}}-{{item[settings.labelKey]}}</label>
119+
<label>{{item.id}} {{item[settings.labelKey]}}</label>
117120
</li>
118121
</ul>
119122
</virtual-scroll>

projects/angular2-multiselect-dropdown-lib/src/lib/multiselect.component.scss

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@ virtual-scroll {
99
display: inline-block;
1010
border-width: 1px;
1111
line-height: 1.25;
12-
/*background: $btn-background;*/
13-
/*border: 1px solid $btn-border;*/
1412
border-radius: 3px;
1513
font-size: 14px;
16-
/*color: $btn-text-color;*/
14+
padding: 5px 10px;
15+
cursor: pointer;
1716
}
1817
.c-btn.disabled{
1918
background: #ccc;
@@ -336,4 +335,16 @@ virtual-scroll {
336335
.loading-icon {
337336
width: 20px;
338337
float: right;
338+
}
339+
.nodata-label {
340+
width: 100%;
341+
text-align: center;
342+
padding: 10px 0px 0px;
343+
}
344+
.btn-container {
345+
text-align: center;
346+
padding: 0px 5px 10px;
347+
}
348+
.btn-iceblue {
349+
339350
}

projects/angular2-multiselect-dropdown-lib/src/lib/multiselect.component.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ export class AngularMultiSelect implements OnInit, ControlValueAccessor, OnChang
7070
@Output('onFilterDeSelectAll')
7171
onFilterDeSelectAll: EventEmitter<Array<any>> = new EventEmitter<Array<any>>();
7272

73+
@Output('onAddFilterNewItem')
74+
onAddFilterNewItem: EventEmitter<any> = new EventEmitter<any>();
75+
7376
@ContentChild(Item) itemTempl: Item;
7477
@ContentChild(Badge) badgeTempl: Badge;
7578
@ContentChild(Search) searchTempl: Search;
@@ -78,6 +81,7 @@ export class AngularMultiSelect implements OnInit, ControlValueAccessor, OnChang
7881
@ViewChild('searchInput') searchInput: ElementRef;
7982
@ViewChild('selectedList') selectedListElem: ElementRef;
8083

84+
filterPipe: ListFilterPipe;
8185
public selectedItems: Array<any>;
8286
public isActive: boolean = false;
8387
public isSelectAll: boolean = false;
@@ -128,7 +132,9 @@ export class AngularMultiSelect implements OnInit, ControlValueAccessor, OnChang
128132
primaryKey: 'id',
129133
position: 'bottom',
130134
enableFilterSelectAll: true,
131-
selectGroup: false
135+
selectGroup: false,
136+
addNewItemOnFilter: false,
137+
addNewButtonText: "Add"
132138
}
133139
public parseError: boolean;
134140
public filteredList: any = [];
@@ -319,8 +325,8 @@ export class AngularMultiSelect implements OnInit, ControlValueAccessor, OnChang
319325
return false;
320326
}
321327
this.isActive = !this.isActive;
322-
if (this.isActive && this.searchInput) {
323-
if (this.settings.searchAutofocus && this.settings.enableSearchFilter && !this.searchTempl) {
328+
if (this.isActive) {
329+
if (this.settings.searchAutofocus && this.searchInput && this.settings.enableSearchFilter && !this.searchTempl) {
324330
setTimeout(() => {
325331
this.searchInput.nativeElement.focus();
326332
}, 0);
@@ -632,6 +638,11 @@ export class AngularMultiSelect implements OnInit, ControlValueAccessor, OnChang
632638
}
633639

634640
}
641+
addFilterNewItem(){
642+
this.onAddFilterNewItem.emit(this.filter);
643+
this.filterPipe = new ListFilterPipe(this.ds);
644+
this.filterPipe.transform(this.data, this.filter, this.settings.searchBy);
645+
}
635646
}
636647

637648
@NgModule({

projects/angular2-multiselect-dropdown-lib/src/lib/multiselect.interface.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,6 @@ export interface DropdownSettings{
2525
position:string;
2626
loading?: boolean;
2727
selectGroup?: boolean;
28+
addNewItemOnFilter?: boolean;
29+
addNewButtonText: string;
2830
}

src/app/app.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
<a [routerLink]="['searchfilter']" routerLinkActive="active" href="#" class="list-group-item list-group-item-action">Search filter</a>
4343
<a [routerLink]="['customSearchAPI']" routerLinkActive="active" href="#" class="list-group-item list-group-item-action">Custom Search / Search API</a>
4444
<a [routerLink]="['searchFilterByOneProperty']" routerLinkActive="active" href="#" class="list-group-item list-group-item-action">Search Filter By one Property/key</a>
45+
<a [routerLink]="['searchfilterAddNewItem']" routerLinkActive="active" href="#" class="list-group-item list-group-item-action">Search and Add New Item</a>
4546
<a [routerLink]="['groupby']" routerLinkActive="active" href="#" class="list-group-item list-group-item-action">Group By</a>
4647
<a [routerLink]="['templating']" routerLinkActive="active" href="#" class="list-group-item list-group-item-action">Templating</a>
4748
<a [routerLink]="['usinginform']" routerLinkActive="active" href="#" class="list-group-item list-group-item-action">Using in Template Driven Forms</a>

src/app/app.module.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import { RemoteDataExample } from './examples/remoteData';
3131
import { CustomSearchExample } from './examples/customSearch';
3232
import { SearchFilterByOnePropertyExample } from './examples/searchByOneProperty';
3333
import {LazyLoadingRemoteDataExample } from './examples/lazyLoadingRemoteData';
34+
import {SearchFilterAddItemExample } from './examples/searchFilterAddNewItem';
3435

3536
@NgModule({
3637
declarations: [
@@ -56,7 +57,8 @@ import {LazyLoadingRemoteDataExample } from './examples/lazyLoadingRemoteData';
5657
RemoteDataExample,
5758
CustomSearchExample,
5859
SearchFilterByOnePropertyExample,
59-
LazyLoadingRemoteDataExample
60+
LazyLoadingRemoteDataExample,
61+
SearchFilterAddItemExample
6062
],
6163
imports: [
6264
BrowserModule,

src/app/app.router.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { RemoteDataExample } from './examples/remoteData';
2323
import { CustomSearchExample } from './examples/customSearch';
2424
import { SearchFilterByOnePropertyExample } from './examples/searchByOneProperty';
2525
import {LazyLoadingRemoteDataExample } from './examples/lazyLoadingRemoteData';
26+
import {SearchFilterAddItemExample } from './examples/searchFilterAddNewItem';
2627

2728
const appRoutes: Routes = [
2829
{ path: '', redirectTo: '/basic', pathMatch: 'full' },
@@ -46,7 +47,8 @@ const appRoutes: Routes = [
4647
{ path: 'remoteData', component: RemoteDataExample },
4748
{ path: 'customSearchAPI', component: CustomSearchExample },
4849
{ path: 'searchFilterByOneProperty', component: SearchFilterByOnePropertyExample },
49-
{ path: 'lazyloadingRemoteData', component: LazyLoadingRemoteDataExample}
50+
{ path: 'lazyloadingRemoteData', component: LazyLoadingRemoteDataExample},
51+
{ path: 'searchfilterAddNewItem', component: SearchFilterAddItemExample}
5052
];
5153

5254

src/app/examples/searchFilter.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ export class SearchFilterExample implements OnInit {
3535
selectAllText: 'Select All',
3636
unSelectAllText: 'UnSelect All',
3737
enableSearchFilter: true,
38-
badgeShowLimit: 3
38+
badgeShowLimit: 3,
39+
addNewItemOnFilter: true
3940
};
4041
}
4142
onItemSelect(item: any) {

0 commit comments

Comments
 (0)