Using dropdown for a column in grid
I have got a dropdown added for a column in a grid. basically works ok. Am using code similar to this example
https://ej2.syncfusion.com/vue/documentation/grid/how-to/cascading-drop-down-list-with-grid-editing/
What I want though is that when I click in the cell to edit it, that the dropdown popup shows immediately so I can start editing. As it is at the moment, the cell gets focus but I have to click in it again to activate the popup.
I tried adding a focus event handler to the drop down when it was created. It sort of worked but not 100%:
self.dropDownList = new ejs.dropdowns.DropDownList({ focus: function (e) { this.showPopup(); } ,I also tried to show pup after appending the dropdown. This did show the dropdown but the popup immediately closed again.
self.dropDownList.appendTo(args.element);setTimeout(function () { self.dropDownList.showPopup();
},1000);
Greetings from Syncfusion support.
Please refer the below code example and sample for more information.
|
<template>
<div id="app">
<ejs-grid
ref="grid"
:dataSource="data"
:editSettings="editSettings"
:toolbar="toolbar"
:actionComplete="actionComplete"
height="273px"
>
<e-columns>
<e-column
field="OrderID"
headerText="Order ID"
:isPrimaryKey="true"
textAlign="Right"
width="100"
></e-column>
<e-column
field="CustomerID"
headerText="Customer ID"
width="120"
></e-column>
<e-column
field="ShipCountry"
headerText="ShipCountry"
editType="dropdownedit"
:edit="countryParams"
width="150"
></e-column>
<e-column
field="ShipCity"
headerText="Ship City"
editType="dropdownedit"
:edit="stateParams"
width="150"
></e-column>
</e-columns>
</ejs-grid>
</div>
</template>
<script>
import Vue from "vue";
import { GridPlugin, Toolbar, Edit } from "@syncfusion/ej2-vue-grids";
import { DropDownList } from "@syncfusion/ej2-dropdowns";
import { Query } from "@syncfusion/ej2-data";
import { data } from "./datasource.js";
let country = [
{ countryName: "United States", countryId: "1" },
{ countryName: "Australia", countryId: "2" },
];
let state = [
{ stateName: "New York", countryId: "1", stateId: "101" },
{ stateName: "Virginia ", countryId: "1", stateId: "102" },
{ stateName: "Washington", countryId: "1", stateId: "103" },
{ stateName: "Queensland", countryId: "2", stateId: "104" },
{ stateName: "Tasmania ", countryId: "2", stateId: "105" },
{ stateName: "Victoria", countryId: "2", stateId: "106" },
];
let countryElem, stateElem, countryObj, stateObj;
Vue.use(GridPlugin);
export default {
data: () => {
return {
data: data,
toolbar: ["Add", "Edit", "Delete", "Update", "Cancel"],
editSettings: {
allowEditing: true,
allowAdding: true,
allowDeleting: true,
},
countryParams: {
create: () => {
countryElem = document.createElement("input");
return countryElem;
},
read: () => {
return countryObj.text;
},
destroy: () => {
countryObj.destroy();
},
write: () => {
countryObj = new DropDownList({
dataSource: country,
fields: { value: "countryId", text: "countryName" },
change: () => {
stateObj.enabled = true;
let tempQuery = new Query().where(
"countryId",
"equal",
countryObj.value
);
stateObj.query = tempQuery;
stateObj.text = null;
stateObj.dataBind();
},
placeholder: "Select a country",
floatLabelType: "Never",
});
countryObj.appendTo(countryElem);
},
},
stateParams: {
create: () => {
stateElem = document.createElement("input");
return stateElem;
},
read: () => {
return stateObj.text;
},
destroy: () => {
stateObj.destroy();
},
write: () => {
stateObj = new DropDownList({
dataSource: state,
fields: { value: "stateId", text: "stateName" },
enabled: false,
placeholder: "Select a state",
floatLabelType: "Never",
});
stateObj.appendTo(stateElem);
},
},
};
},
methods: {
actionComplete(args) {
if (args.requestType === "beginEdit") {
countryObj.showPopup(); // open ship country dropdown popup initially.
}
},
},
provide: {
grid: [Edit, Toolbar],
},
};
</script>
<style>
@import "https://cdn.syncfusion.com/ej2/material.css";
</style> |
Please get back to us if you need further assistance.
Give this a test. The actionComplete fires when edit mode is Normal but I am using Batched (sorry should have specified that but didn't think would make a difference).
Also, the popup should only fire when I move into that cell. At the moment, the popup opens regardless of what column you clicked in.
I tried using the cellEdit event. But it fires BEFORE the dropdown is written (the write() method I mean) so the dropdown is not yet available.
So no solution yet unfortunately.
Thanks for your update.
Please refer the below code example and sample for more information.
|
<template>
<div id="app">
<ejs-grid
ref="grid"
:dataSource="data"
:editSettings="editSettings"
:toolbar="toolbar"
height="273px"
>
<e-columns>
<e-column
field="OrderID"
headerText="Order ID"
:isPrimaryKey="true"
textAlign="Right"
width="100"
></e-column>
<e-column
field="CustomerID"
headerText="Customer ID"
width="120"
></e-column>
<e-column
field="ShipCountry"
headerText="ShipCountry"
editType="dropdownedit"
:edit="countryParams"
width="150"
></e-column>
<e-column
field="ShipCity"
headerText="Ship City"
editType="dropdownedit"
:edit="stateParams"
width="150"
></e-column>
</e-columns>
</ejs-grid>
</div>
</template>
<script>
import Vue from "vue";
import { GridPlugin, Toolbar, Edit } from "@syncfusion/ej2-vue-grids";
import { DropDownList } from "@syncfusion/ej2-dropdowns";
import { Query } from "@syncfusion/ej2-data";
import { data } from "./datasource.js";
let country = [
{ countryName: "United States", countryId: "1" },
{ countryName: "Australia", countryId: "2" },
];
let state = [
{ stateName: "New York", countryId: "1", stateId: "101" },
{ stateName: "Virginia ", countryId: "1", stateId: "102" },
{ stateName: "Washington", countryId: "1", stateId: "103" },
{ stateName: "Queensland", countryId: "2", stateId: "104" },
{ stateName: "Tasmania ", countryId: "2", stateId: "105" },
{ stateName: "Victoria", countryId: "2", stateId: "106" },
];
let countryElem, stateElem, countryObj, stateObj, tempQuery;
Vue.use(GridPlugin);
export default {
data: () => {
return {
data: data,
toolbar: ["Add", "Delete", "Update", "Cancel"],
editSettings: {
allowEditing: true,
allowAdding: true,
allowDeleting: true,
mode: "Batch",
},
countryParams: {
create: () => {
countryElem = document.createElement("input");
return countryElem;
},
read: () => {
return countryObj.text;
},
destroy: () => {
countryObj.destroy();
},
write: (args) => {
countryObj = new DropDownList({
dataSource: country,
fields: { value: "countryId", text: "countryName" },
created: () => {
countryObj.showPopup();
},
change: () => {
tempQuery = new Query().where(
"countryId",
"equal",
countryObj.value
);
},
placeholder: "Select a country",
floatLabelType: "Never",
});
countryObj.appendTo(countryElem);
},
},
stateParams: {
create: () => {
stateElem = document.createElement("input");
return stateElem;
},
read: () => {
return stateObj.text;
},
destroy: () => {
stateObj.destroy();
},
write: () => {
stateObj = new DropDownList({
dataSource: state,
query: tempQuery,
created: () => {
stateObj.showPopup();
},
fields: { value: "stateId", text: "stateName" },
placeholder: "Select a state",
floatLabelType: "Never",
});
stateObj.appendTo(stateElem);
},
},
};
},
methods: {},
provide: {
grid: [Edit, Toolbar],
},
};
</script>
<style>
@import "https://cdn.syncfusion.com/ej2/material.css";
</style> |
Please get back to us if you need further assistance.
Hi Praveenkumar
Close....
Your sample works but I couldn't work out why it didn't work in my code.
Turns out If you add:
allowFiltering: true,
when you create the dropdown in the write() method, it no longer works. This is the case in your sample as well.
Since I need the filtering, this is unfortunately its still not a solution.
Regards
Jeff
Thanks for your patience.
We validated your reported scenario and we can reproduce the reported behavior at our end. We have confirmed this is an issue from our side and logged a bug for the same as “Cell Edit Template is not working when using dropdown component with allowfiltering”. At Syncfusion, we are committed to fixing all validated defects (subject to technical feasibility and Product Development Life Cycle ) and will include the defect fix in our upcoming patch release which will be rolled out on August 18, 2021.
We checked further on your reported issue, for that we suggest you to use the below solution to resolve your reported issue at your end.
In that solution, we are prevent the Grid save action in the Grid’s cellSave event when the dropdown popup is in open state as demonstrated in the below code example.
Please check the below sample and code example for more information.
Code Example:
|
<template>
<div id="app">
<ejs-grid
ref="grid"
id="grid"
:dataSource="data"
:editSettings="editSettings"
:toolbar="toolbar"
:cellSave="cellsave"
height="273px"
>
<e-columns>
....
</e-columns>
</ejs-grid>
</div>
</template>
<script>
Vue.use(GridPlugin); export default {
data: () => {
return {
data: gridData,
toolbar: ["Add", "Delete", "Update", "Cancel"],
editSettings: {
allowEditing: true,
allowAdding: true,
allowDeleting: true,
mode: "Batch",
},
countryParams: {
....
},
stateParams: {
....
}; },
methods: {
cellsave: function (args) {
var gridObj = this.$refs.grid.ej2Instances;
var popElem = document.getElementById(gridObj.element.id + args.columnName + "_popup");
if (popElem && popElem.classList.contains("e-popup-open")) {
args.cancel = true;
}
},
},
provide: {
grid: [Edit, Toolbar],
},
};
</script> |
Sample: https://codesandbox.io/s/requirements-forked-vlwe4?file=/src/App.vue
Regards,
Praveenkumar G
- 7 Replies
- 3 Participants
-
JB Jeff Butterworth
- Jul 16, 2021 01:13 AM UTC
- Aug 12, 2021 05:17 PM UTC