dropdown in editable datatable not holding the selected value

UI Components for Angular
Post Reply
Chi
Posts: 5
Joined: 01 Nov 2017, 05:32

17 Nov 2017, 01:47

Below is the code for the column in the datatable

<p-column field="organization.description" header="Partner" [editable]="dtCostShare" [style]="{'width':'30%'}">
<ng-template let-col let-csp="rowData" pTemplate="editor">
<span class="required-lbl">*
<p-dropdown name="organization" [(ngModel)]="csp.organization.organizationId" (onChange)="addPartnerDescription(csp.index)" [options]="partners" [style]="{'width':'10px'}" appendTo="body" [ngClass]="
{'errorCol':csp.organization.organizationId === ''}">
</p-dropdown>
</span>
<span *ngIf="(csp.organization.organizationId === '' )" class="text-danger">Partner is required</span>
</ng-template>
</p-column>

.ts code to populate the selectItem list for the dropdown
getPartners() {
this.partners.push({ label: 'Please Select', value: '' });
this.parameterService.getPartners().subscribe((data) => {
for (let record of data) {
this.partners.push({ label: record.description, value: record.organizationId });
}
});
}

Whenever i edit the grid the dropdown shows the "Please select" instead of showing the selected Organization name.
When i print the "csp.organization.organizationId" it is giving the selected organizationId but [(ngModel)] doesn't seem to set the selected value. where am i going wrong?

Though the OrganizationId in Organization interface is of type string, the value is coming as int from db. Could this be an issue?

merve7
Posts: 66
Joined: 12 Sep 2017, 10:44

04 Dec 2017, 13:01


Post Reply
  • Information
  • Who is online

    Users browsing this forum: Google [Bot] and 4 guests