|
Index.js
. . . . . . . . .
this.country = [
{ ContactName: "Paul Henriot", CustomerID: "VINET", id: "1" },
{ ContactName: "Karin Josephs", CustomerID: "TOMSP", id: "2" },
{ ContactName: "Mario Pontes", CustomerID: "HANAR", id: "3" },
{ ContactName: "Mary Saveley", CustomerID: "VICTE", id: "4" },
{ ContactName: "Pascale Cartrain", CustomerID: "SUPRD", id: "5" },
{ ContactName: "Yang Wang", CustomerID: "CHOPS", id: "6" }
];
this.stateColl = [
{
CompanyName: "Alfreds Futterkiste",
CustomerID: "VINET",
countryId: "1",
stateId: "101",
Country: "Germany"
},
{
CompanyName: "Ana Trujillo Emparedados y helados",
CustomerID: "TOMSP",
stateId: "102",
Country: "Mexico"
},
{
CompanyName: "Antonio Moreno",
CustomerID: "VINET",
stateId: "103",
Country: "Mexico"
},
{
CompanyName: "Around the Horn",
CustomerID: "HANAR",
stateId: "104",
Country: "UK"
},
{
CompanyName: "Berglunds snabbköp",
CustomerID: "SUPRD",
stateId: "105",
Country: "Sweden"
},
{
CompanyName: "Blauer See Delikatessen",
CustomerID: "CHOPS",
stateId: "106",
Country: "Germany"
},
{
CompanyName: "Blondesddsl père et fils",
CustomerID: "SUPRD",
stateId: "105",
Country: "France"
},
{
CompanyName: "Bólido Comidas preparadas",
CustomerID: "HANAR",
stateId: "106",
Country: "Spain"
},
{
CompanyName: "Blauer See Delikatessen",
CustomerID: "VICTE",
stateId: "106",
Country: "Germany"
}
];
this.countryParams = {
create: () => {
this.countryElem = document.createElement("input");
return this.countryElem;
},
destroy: () => {
this.countryObj.destroy();
},
read: () => {
return this.countryObj.value;
},
write: () => {
this.countryObj = new DropDownList({
change: () => {
this.stateObj.enabled = true;
const tempQuery = new Query().where(
"CustomerID",
"equal",
this.countryObj.value
);
this.stateObj.query = tempQuery; // in the change event of the first dropdown generate query for second dropdown.
this.stateObj.text = "";
this.stateObj.dataBind();
},
dataSource: new DataManager(this.country),
fields: { value: "CustomerID", text: "ContactName" },
floatLabelType: "Never",
placeholder: "Select a country"
});
this.countryObj.appendTo(this.countryElem);
}
};
this.stateParams = {
create: () => {
this.stateElem = document.createElement("input");
return this.stateElem;
},
destroy: () => {
this.stateObj.destroy();
},
read: () => {
return this.stateObj.value;
},
write: () => {
this.stateObj = new DropDownList({
dataSource: new DataManager(this.stateColl),
enabled: false,
fields: { value: "Country", text: "CompanyName" },
floatLabelType: "Never",
placeholder: "Select a state"
});
this.stateObj.appendTo(this.stateElem);
}
};
}
render() {
return (
<div className="control-pane">
<div className="control-section">
<GridComponent
dataSource={orderDetails.slice(0, 8)}
allowPaging={true}
ref={grid => (this.gridInstance = grid)}
allowFiltering={true}
allowSorting={true}
editSettings={{
allowEditing: true,
allowDeleting: true,
allowAdding: true
}}
filterSettings={{ type: "Menu" }}
toolbar={this.toolbarOptions}
>
<ColumnsDirective>
<ColumnDirective
field="OrderID"
headerText="Order ID"
width="120"
textAlign="Right"
validationRules={this.validationRules}
isPrimaryKey={true}
/>
<ColumnDirective
field="CustomerID"
headerText="Customer Name"
width="150"
validationRules={this.validationRules}
foreignKeyValue="ContactName"
foreignKeyField="CustomerID"
dataSource={customerData}
edit={this.countryParams}
/>
<ColumnDirective
field="Country"
headerText="Company Name"
foreignKeyValue="CompanyName"
foreignKeyField="Country"
dataSource={customerData}
edit={this.stateParams}
width="170"
/>
<ColumnDirective
field="Freight"
headerText="Freight"
width="100"
format="C2"
textAlign="Right"
editType="numericedit"
/>
<ColumnDirective
field="ShipCountry"
headerText="Ship Country"
width="150"
editType="dropdownedit"
/>
</ColumnsDirective>
<Inject
services={[Filter, Page, Edit, Sort, ForeignKey, Toolbar]}
/>
</GridComponent>
</div>
</div>
);
}
} |