Using primeNG p-dataview, I have a checkbox and a dropdown for every row. My goal is If I check the checkobox I want to get the value of the dropdon for the selected row (if selectd) same the other way around, If a user select a value from the dropdown I want to see if the checkbox was already checked for this raw. How can I accomplish this ?
HTML
<p-dataView [value]="iErsaDefaultApps" [paginator]="true" [rows]="20" [sortField]="sortField" [sortOrder]="sortOrder" paginatorPosition="both">
<ng-template let-apps let-rowIndexValue="rowIndex" pTemplate="listItem">
<div>
<input type="checkbox" (click)="toggleSelectedApp($event)" id="defaultAppID" name="defaultApps" style="margin-right:5px;margin-bottom:10px;margin-left:5px; margin-top:10px" [value]='apps.app_id'> {{apps.app_name}}
</div>
<div>
<select name="role" class="dropdown" style="width:60%" (ngModelChange)="selectedDefaultAppRole($event,rowIndex)" [(ngModel)]="selectedRole[rowIndex]" >
<option class="dropdown-item" value="" selected>Select</option>
<option class="dropdown-item" *ngFor='let role of apps.roles' [ngValue]="role.app_role_id">
{{role.app_role_name}}
</option>
</select>
</div>
</ng-template>
</p-dataView>
TS
selectedRole: any[] = []
toggleSelectedApp(event: any)
{
//need to check the values of the drpown?
console.log('checkbox' + event.srcElement.checked);
}
}
selectedDefaultAppRole(event: any, index:any) {
//also need to check th value of the checkbox
console.log('selected defult dropdown ' + event);
console.log('selected index ' + event);
}
***********************************************************Update********************************************** 1) selectedDefaultAppRole will not know i the checkbox is checked or not 2) toggleSelectedApp will not know what drpdown value is selected HTML
<p-dataView [value]="iErsaDefaultApps" [paginator]="true" [rows]="20">
<ng-template let-apps let-rowIndexValue="rowIndex" pTemplate="listItem">
<div>
<input type="checkbox" (click)="toggleSelectedApp($event, rowIndexValue)" id="defaultAppID" name="defaultApps"
style="margin-right:5px;margin-bottom:10px;margin-left:5px; margin-top:10px" [value]='apps.app_id'> {{apps.app_name}}
</div>
<div>
<select name="role" class="dropdown" style="width:60%" (ngModelChange)="selectedDefaultAppRole($event, rowIndexValue,apps.app_id)"
[(ngModel)]="selectedRole[rowIndexValue]" >
<option class="dropdown-item" value="" selected>Select</option>
<option class="dropdown-item" *ngFor='let role of apps.roles' [ngValue]="role.app_role_id">
{{role.app_role_name}}
</option>
</select>
</div>
</ng-template>
</p-dataView>
TS 2 issues with
toggleSelectedApp(event: any, rowIndexValue: any)
{
this.selectedObject = this.iErsaAppList
.find(x => x.app_id == event.srcElement.value);
const index: number = this.iErsaDefaultApps.indexOf(this.selectedObject);
const cApp = this.iErsaDefaultApps.filter(a => a.app_id === index);
console.log('currentApp', cApp);
}
selectedDefaultAppRole(event: any, index: number,app_id:number) {
console.log('selected app_id ' + app_id);
const cApp = this.iErsaDefaultApps.filter(a => a.app_id == app_id);
console.log('currentAppRole', cApp);
console.log('currentAppRole', event);
}
interface
export interface IErsaApps {
app_id: number;
app_type_id: number;
app_name: string;
app_roles: string;
app_sort_id?: number;
roles: Array<IErsaAppRoles>
}
export interface IErsaAppRoles {
app_role_id: number;
app_role_app_id: number;
app_role_name: string;
app_role_sort_id?: number;
}