-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(igx-combo): implement filtering with pipes, WIP, #1260
- Loading branch information
1 parent
a6b54af
commit 7133f3e
Showing
5 changed files
with
167 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
.small-red-circle { | ||
background-color: #FF2344; | ||
margin: 2% 5px 2% 0px; | ||
width: 5px; | ||
height: 5px; | ||
border-radius: 50%; | ||
vertical-align: middle; | ||
display: inline-block; | ||
} | ||
|
||
.footer-class, .header-class { | ||
color: #131313; | ||
background-color: #d3d3d3; | ||
cursor: not-allowed; | ||
text-align: center; | ||
font-weight: 400; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,22 @@ | ||
<ng-template #myCustomTemplate let-display let-key="primaryKey"> | ||
<div>I live in {{display[key]}}</div> | ||
</ng-template> | ||
<div class="sample-wrapper"> | ||
<page-header title="Combo" description="Combo lets you choose value from a list"></page-header> | ||
<section class="sample-content"> | ||
<p>Change data to:</p> | ||
<button class="igx-button" (click)="changeData('primitive')">Primitve</button> | ||
<button class="igx-button" (click)="changeData('complex')">Complex</button> | ||
<button class="igx-button" (click)="changeData()">Initial</button> | ||
<igx-combo [data]="items" [filter]="true" [primaryKey]="'field'" [customTemplate]="myCustomTemplate"></igx-combo> | ||
<igx-combo [placeholder]="'Location'" [data]="items" [filterable]="true" [primaryKey]="'field'" [width]="'400px'"> | ||
<ng-template #dropdownItemTemplate let-display let-key="primaryKey"> | ||
<div> | ||
<span class="small-red-circle"></span>{{display[key]}} | ||
</div> | ||
</ng-template> | ||
<ng-template #dropdownFooter> | ||
<div class="footer-class">This is a footer</div> | ||
</ng-template> | ||
<ng-template #dropdownHeader> | ||
<div class="header-class">This is a header</div> | ||
</ng-template> | ||
</igx-combo> | ||
</section> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { Pipe, PipeTransform } from "@angular/core"; | ||
import { cloneArray } from "../core/utils"; | ||
import { DataUtil } from "../data-operations/data-util"; | ||
import { FilteringLogic, IFilteringExpression } from "../data-operations/filtering-expression.interface"; | ||
import { IgxComboComponent } from "../main"; | ||
|
||
@Pipe({ | ||
name: "comboFiltering", | ||
pure: true | ||
}) | ||
export class IgxComboFilteringPipe implements PipeTransform { | ||
|
||
constructor() {} | ||
|
||
public transform(collection: any[], expressions: IFilteringExpression | IFilteringExpression[], | ||
logic: FilteringLogic, caller: IgxComboComponent, pipeTrigger: number) { | ||
const state = { expressions: [], logic }; | ||
state.expressions = caller.filteringExpressions; | ||
|
||
if (!state.expressions.length) { | ||
return collection; | ||
} | ||
|
||
const result = DataUtil.filter(cloneArray(collection), state); | ||
caller.filteredData = result; | ||
return result; | ||
} | ||
} | ||
|
||
@Pipe({ | ||
name: "filterCondition", | ||
pure: true | ||
}) | ||
|
||
export class IgxComboFilterConditionPipe implements PipeTransform { | ||
|
||
public transform(value: string): string { | ||
return value.split(/(?=[A-Z])/).join(" "); | ||
} | ||
} |