I'm trying to bind some simple data to a dropdown when editing a row in the grid, but I can't seem to get it to work.
Here is the component.html part<ej-grid [allowPaging]="true" [pageSettings]="pageSettings" [allowSelection]="true"
[allowGrouping]="true" [allowSorting]="true" [allowFiltering]="true" [allowResizing]="true" [allowReordering]="true" [allowSearching]="true"
[allowMultipleExporting]="true" [showColumnChooser]="true"
[toolbarSettings]="toolbarItems" [editSettings]="editSettings"
[filterSettings]="filterType" [groupSettings.groupedColumns]="groupedColumns" [dataSource]="gridData">
<e-columns>
<e-column field="ID" [isPrimaryKey]="true" editType="numericedit" headerText="ID" width="10" textAlign="right"></e-column>
<e-column field="Firstname" headerText="First Name" width="40"></e-column>
<e-column field="Surname" headerText="Surname" width="40"></e-column>
<e-column field="Gender" editType="dropdownedit" [editParams] ="{enableAnimation: true}" dataSource="genderData" headerText="Gender" width="10"></e-column>
<e-column field="DateOfBirth" editType="datepicker" format="{0:dd/MM/yyyy}" headerText="Date of Birth" width="20"></e-column>
</e-columns>
</ej-grid>
So, I'm trying to bind the Gender dropdown to a genderData data source.
This is the component.ts part
import { Component } from '@angular/core';
import { TheGang, TheGangService } from '../service/thegang.service';
import { Gender, GenderService } from '../service/gender.service';
@Component({
selector: 'app-editgrid3',
templateUrl: './editgrid3.component.html',
styleUrls: ['./editgrid3.component.scss'],
providers: [TheGangService, GenderService]
})
export class EditGrid3Component {
public gridData: any;
public genderData: any;
public groupedColumns: Array;
public filterType;
public pageSettings;
public editSettings;
public toolbarItems;
gangmembers: TheGang[]
genders: Gender[]
constructor(theGangService: TheGangService, GenderService: GenderService) {
this.gangmembers = theGangService.getTheGang();
this.genders = GenderService.getGenders();
this.filterType = { filterType: 'menu' };
this.pageSettings = { pageSize: 5 };
this.editSettings = { allowEditing: true, allowAdding: true, allowDeleting: true, editMode: "dialog", showDeleteConfirmDialog:true };
this.toolbarItems = { showToolbar: true, toolbarItems: ["add", "edit", "delete", "update", "cancel", "search"] };
this.genderData = this.genders;
this.gridData = this.gangmembers;
}
}
However, when it all runs my dropdown is empty.
Any ideas where I am going wrong?
Dave
<h2>Syncfusion Javascript Angular 2 Component</h2>
<ej-grid #grid [dataSource]="gridData" [allowPaging]="true" [pageSettings]="pageSettings" [allowSelection]="true"
... (actionComplete)="onComplete($event)" >
<e-columns>
...
<e-column field="EmployeeID" editType="dropdownedit" headerText="EmployeeID" [dataSource]="foreignData" width="75" textAlign="right"></e-column>
</e-columns>
</ej-grid>
[app.component.ts]
export class AppComponent {
public groupedColumns: Array;
...
public toolbarItems = { showToolbar: true, toolbarItems: [ej.Grid.ToolBarItems.Add, ej.Grid.ToolBarItems.Edit, ej.Grid.ToolBarItems.Delete, ej.Grid.ToolBarItems.Update, ej.Grid.ToolBarItems.Cancel] };
public editSettings = { allowEditing: true, allowAdding: true, allowDeleting: true, editMode: "dialog" };
public gridData = window.gridData;
onComplete(event: any) {
if (event.requestType == "beginedit") {
$("#ejControl_0EmployeeID").ejDropDownList({ dataSource: event.model.columns[2].dataSource, fields: { text: "EmployeeID", value: "EmployeeID" } }).ejDropDownList("setSelectedValue", event.row.children().eq(2).text());
//bind the data for the dropdown with text and value pair
//setSelectedValue is to shown current value for the row
}
}
...
|
Manisankar,
Thanks for the reply. Unfortunately I still can't get it to work, it still is not showing any data in the drop down. I've attempted to follow the example and have now got the following code:
app.component.ts
import { Component } from '@angular/core';
import { TheGang, TheGangService } from '../service/thegang.service';
import { Gender, GenderService } from '../service/gender.service';
@Component({
selector: 'app-editgrid3',
templateUrl: './editgrid3.component.html',
styleUrls: ['./editgrid3.component.scss'],
providers: [TheGangService, GenderService]
})
export class EditGrid3Component {
public gridData: any;
public genderData: any;
public groupedColumns: Array<string>;
public filterType;
public pageSettings;
public editSettings;
public toolbarItems;
gangmembers: TheGang[]
genders: Gender[]
constructor(theGangService: TheGangService, GenderService: GenderService) {
this.gangmembers = theGangService.getTheGang();
this.genders = GenderService.getGenders();
this.filterType = { filterType: 'menu' };
this.pageSettings = { pageSize: 5 };
this.editSettings = { allowEditing: true, allowAdding: true, allowDeleting: true, editMode: "dialog", showDeleteConfirmDialog:true };
this.toolbarItems = { showToolbar: true, toolbarItems: ["add", "edit", "delete", "update", "cancel", "search"] };
this.genderData = this.genders;
this.gridData = this.gangmembers;
}
onComplete(event: any) {
if (event.requestType == "beginedit") {
$("#ejControl_0Gender").ejDropDownList({ dataSource: event.model.columns[2].dataSource, fields: { text: "Text", value: "Value" } }).ejDropDownList("setSelectedValue", event.row.children().eq(2).text());
}
}
}
app.component.html
<h1>Edit Grid 3</h1>
<p>Edit with a modal popup diaog</p>
<ej-grid [allowPaging]="true" [pageSettings]="pageSettings" [allowSelection]="true"
[allowGrouping]="true" [allowSorting]="true" [allowFiltering]="true" [allowResizing]="true" [allowReordering]="true" [allowSearching]="true"
[allowMultipleExporting]="true" [showColumnChooser]="true"
[toolbarSettings]="toolbarItems" [editSettings]="editSettings"
[filterSettings]="filterType" [groupSettings.groupedColumns]="groupedColumns" [dataSource]="gridData"
(actionComplete)="onComplete($event)" >
<e-columns>
<e-column field="ID" [isPrimaryKey]="true" editType="numericedit" headerText="ID" width="10" textAlign="right"></e-column>
<e-column field="Firstname" headerText="First Name" width="40"></e-column>
<e-column field="Surname" headerText="Surname" width="40"></e-column>
<e-column field="Gender" editType="dropdownedit" [editParams] ="{enableAnimation: true}" dataSource="genderData" headerText="Gender" width="10"></e-column>
<e-column field="DateOfBirth" editType="datepicker" format="{0:dd/MM/yyyy}" headerText="Date of Birth" width="20"></e-column>
</e-columns>
</ej-grid>
Any idea why this is still not working for me?
Dave
onComplete(event: any) {
if (event.requestType == "beginedit") {
$("#ejControl_0EmployeeID").ejDropDownList({ dataSource: event.model.columns[this.Grid.widget.getColumnIndexByField("EmployeeID")].dataSource, fields: { text: "EmployeeID", value: "EmployeeID" } }).ejDropDownList("setSelectedValue", event.row.children().eq(2).text());
//bind the data for the dropdown with text and value pair
//setSelectedValue is to shown current value for the row
}
} |
Jayaprakas,
Thanks for the reply.
I have simply changed the 2 to a 3, but it is still not working. When the edit dialog opens when you click the dropdown it just has "undefined".
Dave
Manisanka,
I've cut back on the code and removed the previous datasource and replaced it with a simple array:
public genderData = [{ Gender: "M" }, { Gender: "F" }];
I've then modifed the code to set both the Value and Text to "Gender"
$("#ejControl_0Gender").ejDropDownList({ dataSource: event.model.columns[3].dataSource, fields: { text: "Gender", value: "Gender" } }).ejDropDownList("setSelectedValue", event.row.children().eq(3).text());
However, I'm still getting the dropdown saying undefined.
I've attached a zip file containing the code and a screenshot.
Dave
<ej-grid [allowPaging]="true" [pageSettings]="pageSettings" [allowSelection]="true"
...
[dataSource]="gridData"
(actionComplete)="onComplete($event)" >
<e-columns>
...
<e-column field="Gender" editType="dropdownedit" [editParams] ="{enableAnimation: true}" [dataSource]="genderData" headerText="Gender" width="10"></e-column>
//dataSource must be mentioned as [dataSource].
...
</e-columns>
</ej-grid> |
Manisanka,
Thank you that has fixed it.
Can't believe it was something as innocuous as not having square brackets.
Dave