Hi guys I’m basically trying to create a custom cell editor for ag-grid, i want to use a custom dropdown using ant design, but i cannot make it work, i’m displaying the values in my screeen in the cell, but unfortunately i cannot set the value when clicking on it, i’m pretty new with at coding so if someone can help me out with this it would be very helpful (if ther’s something else i need to add so that it can be more understandable please tell me)
This is basically the table
import DropdownComponent from "containers/sensitivityanalysis/DropdownCell";
const ParametersListsTable: React.FC = () => {
const [rowData, setRowData] = useState([{}]);
const [columnDefs, setColumnDefs] = useState<ColDef[]>([
{
field: "Description",
headerName: "Description",
width: 200,
cellEditor: DropdownComponent,
cellEditorParams: {
values: [
"Manifold Pressure",
"Reservoir Pressure",
"Bubble Point Pressure",
"FBHP",
"Liquid Rate",
"Total Gas Rate",
"Oil Rate",
"Formation Gas Rate",
"Limit Lift Meas Depth",
"SG Formation Gas",
"SG Water",
"Oil API Gravity",
"Static Surface Temp.",
"BHT",
"Choke Coefficient",
"Surface Temperature",
"Operating Mandre Number",
"OPerating Valve Throughput",
"SBHP",
"Bean Size",
"Minimum Require LG Rate",
"Tubing Sizing",
"Diameter For Lifting",
],
},
},
]);
const defaultColDef = useMemo(() => {
return {
resizable: true,
filter: true,
editable: true,
};
}, []);
And this is my custom dropdown
import { Select } from "antd";
import { useState } from "react";
const { Option } = Select;
const DropdownComponent = (props) => {
const [selection, setSelection] = useState();
const handleDropDown = (e) => {
setSelection(e.target.value);
};
return (
<Select
style={{ width: "100%", height: "100%" }}
onClick={handleDropDown}
value={selection}
>
{props.values.map((item) => (
<Option key={item} value={item}>
{item}
</Option>
))}
</Select>
);
};
export default DropdownComponent;
2
Answers
I came up with a solution reading some stuff from the documentation and checking on some examples that i found on it
This is my cell editor custom component:
And I'm simply using it this way
You’re on the wrong path to overcome this issue.
First, I am going to define the DropdownRenderer component
As to its column definition
Result:
Here’s a working plunker: https://plnkr.co/edit/7LJ6G8ShGRkjDJLE?preview