How do I filter using user selected value with Angular Material Select?
I am trying to create a dropdown filter in angular material. Here is the array for my dropdown options
public intensities = ['All',1,2,3,4,5]
Here is the html for the mat-select field.
<mat-form-field>
<mat-select placeholder="Choose Intensity" [(ngModel)]="selectedIntensity" (selectionChange)="onIntensityChange()">
<mat-option *ngFor="let intensity of intensities" [value]="intensity">
{{intensity}}
</mat-option>
</mat-select>
</mat-form-field>
<div class="flex-wrap" style="display: inline-block; padding: 5px 0 5px 20px;">
<span style="font-weight:bold;">Show Shoppers With: </span>
<input style="margin-left: 10px; margin-right: 5px;" type="checkbox" [(ngModel)]="hiddenWithoutPhone" (change)="filterVisibleShoppers()">Phone
<input style="margin-left: 10px; margin-right: 5px;" type="checkbox" [(ngModel)]="hiddenWithoutEmail" (change)="filterVisibleShoppers()">Email
<input style="margin-left: 10px; margin-right: 5px;" type="checkbox" [(ngModel)]="hiddenWithoutAddress" (change)="filterVisibleShoppers()">Address
<input style="margin-left: 10px; margin-right: 5px;" type="checkbox" [(ngModel)]="hiddenWithoutTradeIn" (change)="filterVisibleShoppers()">Trade In
</div>
I am trying to write a function 'onIntensityChange()' that displays the correct choices based on the user selection. I also have a filter that works with a checkbox. I'd like to be able to filter based on both selections(dropdown and checkbox) Here is the typescript file.
@Component({
templateUrl: 'daily-active-shopper.screen.html',
})
export class DailyActiveShoppersScreen {
public selectedDate: Date;
public maxDate: Date = new Date();
public count = 0;
public customers;
public loading: boolean;
public hiddenWithoutEmail: boolean;
public hiddenWithoutPhone: boolean;
public hiddenWithoutAddress: boolean;
public hiddenWithoutTradeIn: boolean;
_dealerId: number;
activeShopperDay: DailyActiveShopperDay;
visibleActiveShoppers: DailyActiveShopper;
shopperDetailsVisible = true;
shopperErrorMessage: string;
public intensities = ['All',1,2,3,4,5]
public selectedIntensity: any;
filterVisibleShoppers() {
let shoppers = this.activeShopperDay.shoppers;
if (this.hiddenWithoutAddress) {
shoppers = shoppers.filter((shopper) => {
return shopper.state !== null;
});
}
if (this.hiddenWithoutPhone) {
shoppers = shoppers.filter((shopper) => {
return shopper.phone !== null;
});
}
if (this.hiddenWithoutEmail) {
shoppers = shoppers.filter((shopper) => {
return shopper.email !== null;
});
}
if (this.hiddenWithoutTradeIn) {
shoppers = shoppers.filter((shopper) => {
return shopper.currentVehicle;
});
}
this.visibleActiveShoppers = shoppers;
}
onIntensityChange() {
console.log(this.selectedIntensity);
let shoppers = this.activeShopperDay.shoppers;
if(this.selectedIntensity === 'All') {
shoppers = shoppers.filter((shopper) => {
return this.visibleActiveShoppers = shoppers;
})
}
if(this.selectedIntensity === 1) {
shoppers = shoppers.filter((shopper) => {
return shopper.intensity === this.selectedIntensity
})
}
if(this.selectedIntensity === 2) {
shoppers = shoppers.filter((shopper) => {
return shopper.intensity === this.selectedIntensity
})
}
if(this.selectedIntensity === 3) {
shoppers = shoppers.filter((shopper) => {
return shopper.intensity === this.selectedIntensity
})
}
if(this.selectedIntensity === 4) {
shoppers = shoppers.filter((shopper) => {
return shopper.intensity === this.selectedIntensity
})
}
if(this.selectedIntensity === 5) {
shoppers = shoppers.filter((shopper) => {
return shopper.intensity === this.selectedIntensity
})
}
if(this.visibleActiveShoppers.length < 1) {
console.log("None found for this intensity")
}
this.visibleActiveShoppers = shoppers;
}
I'm looking for a proper way to implement this. Basically allowing the user to filter based on intensity and the four radio buttons.
javascript html angular typescript
|
show 2 more comments
I am trying to create a dropdown filter in angular material. Here is the array for my dropdown options
public intensities = ['All',1,2,3,4,5]
Here is the html for the mat-select field.
<mat-form-field>
<mat-select placeholder="Choose Intensity" [(ngModel)]="selectedIntensity" (selectionChange)="onIntensityChange()">
<mat-option *ngFor="let intensity of intensities" [value]="intensity">
{{intensity}}
</mat-option>
</mat-select>
</mat-form-field>
<div class="flex-wrap" style="display: inline-block; padding: 5px 0 5px 20px;">
<span style="font-weight:bold;">Show Shoppers With: </span>
<input style="margin-left: 10px; margin-right: 5px;" type="checkbox" [(ngModel)]="hiddenWithoutPhone" (change)="filterVisibleShoppers()">Phone
<input style="margin-left: 10px; margin-right: 5px;" type="checkbox" [(ngModel)]="hiddenWithoutEmail" (change)="filterVisibleShoppers()">Email
<input style="margin-left: 10px; margin-right: 5px;" type="checkbox" [(ngModel)]="hiddenWithoutAddress" (change)="filterVisibleShoppers()">Address
<input style="margin-left: 10px; margin-right: 5px;" type="checkbox" [(ngModel)]="hiddenWithoutTradeIn" (change)="filterVisibleShoppers()">Trade In
</div>
I am trying to write a function 'onIntensityChange()' that displays the correct choices based on the user selection. I also have a filter that works with a checkbox. I'd like to be able to filter based on both selections(dropdown and checkbox) Here is the typescript file.
@Component({
templateUrl: 'daily-active-shopper.screen.html',
})
export class DailyActiveShoppersScreen {
public selectedDate: Date;
public maxDate: Date = new Date();
public count = 0;
public customers;
public loading: boolean;
public hiddenWithoutEmail: boolean;
public hiddenWithoutPhone: boolean;
public hiddenWithoutAddress: boolean;
public hiddenWithoutTradeIn: boolean;
_dealerId: number;
activeShopperDay: DailyActiveShopperDay;
visibleActiveShoppers: DailyActiveShopper;
shopperDetailsVisible = true;
shopperErrorMessage: string;
public intensities = ['All',1,2,3,4,5]
public selectedIntensity: any;
filterVisibleShoppers() {
let shoppers = this.activeShopperDay.shoppers;
if (this.hiddenWithoutAddress) {
shoppers = shoppers.filter((shopper) => {
return shopper.state !== null;
});
}
if (this.hiddenWithoutPhone) {
shoppers = shoppers.filter((shopper) => {
return shopper.phone !== null;
});
}
if (this.hiddenWithoutEmail) {
shoppers = shoppers.filter((shopper) => {
return shopper.email !== null;
});
}
if (this.hiddenWithoutTradeIn) {
shoppers = shoppers.filter((shopper) => {
return shopper.currentVehicle;
});
}
this.visibleActiveShoppers = shoppers;
}
onIntensityChange() {
console.log(this.selectedIntensity);
let shoppers = this.activeShopperDay.shoppers;
if(this.selectedIntensity === 'All') {
shoppers = shoppers.filter((shopper) => {
return this.visibleActiveShoppers = shoppers;
})
}
if(this.selectedIntensity === 1) {
shoppers = shoppers.filter((shopper) => {
return shopper.intensity === this.selectedIntensity
})
}
if(this.selectedIntensity === 2) {
shoppers = shoppers.filter((shopper) => {
return shopper.intensity === this.selectedIntensity
})
}
if(this.selectedIntensity === 3) {
shoppers = shoppers.filter((shopper) => {
return shopper.intensity === this.selectedIntensity
})
}
if(this.selectedIntensity === 4) {
shoppers = shoppers.filter((shopper) => {
return shopper.intensity === this.selectedIntensity
})
}
if(this.selectedIntensity === 5) {
shoppers = shoppers.filter((shopper) => {
return shopper.intensity === this.selectedIntensity
})
}
if(this.visibleActiveShoppers.length < 1) {
console.log("None found for this intensity")
}
this.visibleActiveShoppers = shoppers;
}
I'm looking for a proper way to implement this. Basically allowing the user to filter based on intensity and the four radio buttons.
javascript html angular typescript
Could you please add the rest of your TS part ?
– selem mn
Nov 14 '18 at 22:46
Do you need the entire file? I am also wanting to filter using radio buttons as well.
– LDB
Nov 14 '18 at 22:58
There is some undefined -for me at least- variables, such asactiveShopperDay
,visibleActiveShoppers
.. so yes if you want !
– selem mn
Nov 14 '18 at 23:01
1
Does this help. I've added more of the TS file.
– LDB
Nov 14 '18 at 23:09
Here is a stackblitz for your case , try to add there your missed modelsDailyActiveShopperDay
andDailyActiveShopper
.
– selem mn
Nov 14 '18 at 23:33
|
show 2 more comments
I am trying to create a dropdown filter in angular material. Here is the array for my dropdown options
public intensities = ['All',1,2,3,4,5]
Here is the html for the mat-select field.
<mat-form-field>
<mat-select placeholder="Choose Intensity" [(ngModel)]="selectedIntensity" (selectionChange)="onIntensityChange()">
<mat-option *ngFor="let intensity of intensities" [value]="intensity">
{{intensity}}
</mat-option>
</mat-select>
</mat-form-field>
<div class="flex-wrap" style="display: inline-block; padding: 5px 0 5px 20px;">
<span style="font-weight:bold;">Show Shoppers With: </span>
<input style="margin-left: 10px; margin-right: 5px;" type="checkbox" [(ngModel)]="hiddenWithoutPhone" (change)="filterVisibleShoppers()">Phone
<input style="margin-left: 10px; margin-right: 5px;" type="checkbox" [(ngModel)]="hiddenWithoutEmail" (change)="filterVisibleShoppers()">Email
<input style="margin-left: 10px; margin-right: 5px;" type="checkbox" [(ngModel)]="hiddenWithoutAddress" (change)="filterVisibleShoppers()">Address
<input style="margin-left: 10px; margin-right: 5px;" type="checkbox" [(ngModel)]="hiddenWithoutTradeIn" (change)="filterVisibleShoppers()">Trade In
</div>
I am trying to write a function 'onIntensityChange()' that displays the correct choices based on the user selection. I also have a filter that works with a checkbox. I'd like to be able to filter based on both selections(dropdown and checkbox) Here is the typescript file.
@Component({
templateUrl: 'daily-active-shopper.screen.html',
})
export class DailyActiveShoppersScreen {
public selectedDate: Date;
public maxDate: Date = new Date();
public count = 0;
public customers;
public loading: boolean;
public hiddenWithoutEmail: boolean;
public hiddenWithoutPhone: boolean;
public hiddenWithoutAddress: boolean;
public hiddenWithoutTradeIn: boolean;
_dealerId: number;
activeShopperDay: DailyActiveShopperDay;
visibleActiveShoppers: DailyActiveShopper;
shopperDetailsVisible = true;
shopperErrorMessage: string;
public intensities = ['All',1,2,3,4,5]
public selectedIntensity: any;
filterVisibleShoppers() {
let shoppers = this.activeShopperDay.shoppers;
if (this.hiddenWithoutAddress) {
shoppers = shoppers.filter((shopper) => {
return shopper.state !== null;
});
}
if (this.hiddenWithoutPhone) {
shoppers = shoppers.filter((shopper) => {
return shopper.phone !== null;
});
}
if (this.hiddenWithoutEmail) {
shoppers = shoppers.filter((shopper) => {
return shopper.email !== null;
});
}
if (this.hiddenWithoutTradeIn) {
shoppers = shoppers.filter((shopper) => {
return shopper.currentVehicle;
});
}
this.visibleActiveShoppers = shoppers;
}
onIntensityChange() {
console.log(this.selectedIntensity);
let shoppers = this.activeShopperDay.shoppers;
if(this.selectedIntensity === 'All') {
shoppers = shoppers.filter((shopper) => {
return this.visibleActiveShoppers = shoppers;
})
}
if(this.selectedIntensity === 1) {
shoppers = shoppers.filter((shopper) => {
return shopper.intensity === this.selectedIntensity
})
}
if(this.selectedIntensity === 2) {
shoppers = shoppers.filter((shopper) => {
return shopper.intensity === this.selectedIntensity
})
}
if(this.selectedIntensity === 3) {
shoppers = shoppers.filter((shopper) => {
return shopper.intensity === this.selectedIntensity
})
}
if(this.selectedIntensity === 4) {
shoppers = shoppers.filter((shopper) => {
return shopper.intensity === this.selectedIntensity
})
}
if(this.selectedIntensity === 5) {
shoppers = shoppers.filter((shopper) => {
return shopper.intensity === this.selectedIntensity
})
}
if(this.visibleActiveShoppers.length < 1) {
console.log("None found for this intensity")
}
this.visibleActiveShoppers = shoppers;
}
I'm looking for a proper way to implement this. Basically allowing the user to filter based on intensity and the four radio buttons.
javascript html angular typescript
I am trying to create a dropdown filter in angular material. Here is the array for my dropdown options
public intensities = ['All',1,2,3,4,5]
Here is the html for the mat-select field.
<mat-form-field>
<mat-select placeholder="Choose Intensity" [(ngModel)]="selectedIntensity" (selectionChange)="onIntensityChange()">
<mat-option *ngFor="let intensity of intensities" [value]="intensity">
{{intensity}}
</mat-option>
</mat-select>
</mat-form-field>
<div class="flex-wrap" style="display: inline-block; padding: 5px 0 5px 20px;">
<span style="font-weight:bold;">Show Shoppers With: </span>
<input style="margin-left: 10px; margin-right: 5px;" type="checkbox" [(ngModel)]="hiddenWithoutPhone" (change)="filterVisibleShoppers()">Phone
<input style="margin-left: 10px; margin-right: 5px;" type="checkbox" [(ngModel)]="hiddenWithoutEmail" (change)="filterVisibleShoppers()">Email
<input style="margin-left: 10px; margin-right: 5px;" type="checkbox" [(ngModel)]="hiddenWithoutAddress" (change)="filterVisibleShoppers()">Address
<input style="margin-left: 10px; margin-right: 5px;" type="checkbox" [(ngModel)]="hiddenWithoutTradeIn" (change)="filterVisibleShoppers()">Trade In
</div>
I am trying to write a function 'onIntensityChange()' that displays the correct choices based on the user selection. I also have a filter that works with a checkbox. I'd like to be able to filter based on both selections(dropdown and checkbox) Here is the typescript file.
@Component({
templateUrl: 'daily-active-shopper.screen.html',
})
export class DailyActiveShoppersScreen {
public selectedDate: Date;
public maxDate: Date = new Date();
public count = 0;
public customers;
public loading: boolean;
public hiddenWithoutEmail: boolean;
public hiddenWithoutPhone: boolean;
public hiddenWithoutAddress: boolean;
public hiddenWithoutTradeIn: boolean;
_dealerId: number;
activeShopperDay: DailyActiveShopperDay;
visibleActiveShoppers: DailyActiveShopper;
shopperDetailsVisible = true;
shopperErrorMessage: string;
public intensities = ['All',1,2,3,4,5]
public selectedIntensity: any;
filterVisibleShoppers() {
let shoppers = this.activeShopperDay.shoppers;
if (this.hiddenWithoutAddress) {
shoppers = shoppers.filter((shopper) => {
return shopper.state !== null;
});
}
if (this.hiddenWithoutPhone) {
shoppers = shoppers.filter((shopper) => {
return shopper.phone !== null;
});
}
if (this.hiddenWithoutEmail) {
shoppers = shoppers.filter((shopper) => {
return shopper.email !== null;
});
}
if (this.hiddenWithoutTradeIn) {
shoppers = shoppers.filter((shopper) => {
return shopper.currentVehicle;
});
}
this.visibleActiveShoppers = shoppers;
}
onIntensityChange() {
console.log(this.selectedIntensity);
let shoppers = this.activeShopperDay.shoppers;
if(this.selectedIntensity === 'All') {
shoppers = shoppers.filter((shopper) => {
return this.visibleActiveShoppers = shoppers;
})
}
if(this.selectedIntensity === 1) {
shoppers = shoppers.filter((shopper) => {
return shopper.intensity === this.selectedIntensity
})
}
if(this.selectedIntensity === 2) {
shoppers = shoppers.filter((shopper) => {
return shopper.intensity === this.selectedIntensity
})
}
if(this.selectedIntensity === 3) {
shoppers = shoppers.filter((shopper) => {
return shopper.intensity === this.selectedIntensity
})
}
if(this.selectedIntensity === 4) {
shoppers = shoppers.filter((shopper) => {
return shopper.intensity === this.selectedIntensity
})
}
if(this.selectedIntensity === 5) {
shoppers = shoppers.filter((shopper) => {
return shopper.intensity === this.selectedIntensity
})
}
if(this.visibleActiveShoppers.length < 1) {
console.log("None found for this intensity")
}
this.visibleActiveShoppers = shoppers;
}
I'm looking for a proper way to implement this. Basically allowing the user to filter based on intensity and the four radio buttons.
javascript html angular typescript
javascript html angular typescript
edited Nov 14 '18 at 23:07
LDB
asked Nov 14 '18 at 22:06
LDBLDB
41110
41110
Could you please add the rest of your TS part ?
– selem mn
Nov 14 '18 at 22:46
Do you need the entire file? I am also wanting to filter using radio buttons as well.
– LDB
Nov 14 '18 at 22:58
There is some undefined -for me at least- variables, such asactiveShopperDay
,visibleActiveShoppers
.. so yes if you want !
– selem mn
Nov 14 '18 at 23:01
1
Does this help. I've added more of the TS file.
– LDB
Nov 14 '18 at 23:09
Here is a stackblitz for your case , try to add there your missed modelsDailyActiveShopperDay
andDailyActiveShopper
.
– selem mn
Nov 14 '18 at 23:33
|
show 2 more comments
Could you please add the rest of your TS part ?
– selem mn
Nov 14 '18 at 22:46
Do you need the entire file? I am also wanting to filter using radio buttons as well.
– LDB
Nov 14 '18 at 22:58
There is some undefined -for me at least- variables, such asactiveShopperDay
,visibleActiveShoppers
.. so yes if you want !
– selem mn
Nov 14 '18 at 23:01
1
Does this help. I've added more of the TS file.
– LDB
Nov 14 '18 at 23:09
Here is a stackblitz for your case , try to add there your missed modelsDailyActiveShopperDay
andDailyActiveShopper
.
– selem mn
Nov 14 '18 at 23:33
Could you please add the rest of your TS part ?
– selem mn
Nov 14 '18 at 22:46
Could you please add the rest of your TS part ?
– selem mn
Nov 14 '18 at 22:46
Do you need the entire file? I am also wanting to filter using radio buttons as well.
– LDB
Nov 14 '18 at 22:58
Do you need the entire file? I am also wanting to filter using radio buttons as well.
– LDB
Nov 14 '18 at 22:58
There is some undefined -for me at least- variables, such as
activeShopperDay
, visibleActiveShoppers
.. so yes if you want !– selem mn
Nov 14 '18 at 23:01
There is some undefined -for me at least- variables, such as
activeShopperDay
, visibleActiveShoppers
.. so yes if you want !– selem mn
Nov 14 '18 at 23:01
1
1
Does this help. I've added more of the TS file.
– LDB
Nov 14 '18 at 23:09
Does this help. I've added more of the TS file.
– LDB
Nov 14 '18 at 23:09
Here is a stackblitz for your case , try to add there your missed models
DailyActiveShopperDay
and DailyActiveShopper
.– selem mn
Nov 14 '18 at 23:33
Here is a stackblitz for your case , try to add there your missed models
DailyActiveShopperDay
and DailyActiveShopper
.– selem mn
Nov 14 '18 at 23:33
|
show 2 more comments
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53309436%2fhow-do-i-filter-using-user-selected-value-with-angular-material-select%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53309436%2fhow-do-i-filter-using-user-selected-value-with-angular-material-select%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Could you please add the rest of your TS part ?
– selem mn
Nov 14 '18 at 22:46
Do you need the entire file? I am also wanting to filter using radio buttons as well.
– LDB
Nov 14 '18 at 22:58
There is some undefined -for me at least- variables, such as
activeShopperDay
,visibleActiveShoppers
.. so yes if you want !– selem mn
Nov 14 '18 at 23:01
1
Does this help. I've added more of the TS file.
– LDB
Nov 14 '18 at 23:09
Here is a stackblitz for your case , try to add there your missed models
DailyActiveShopperDay
andDailyActiveShopper
.– selem mn
Nov 14 '18 at 23:33