New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for React Hooks #27
Comments
The answer is: function onFieldChange(rowId, field, value) {
// Find a row that is being changed
const row = rows.find(({id}) => id === rowId);
// Change a value of a field
row[field] = value;
setRows([].concat(rows));
// Blurring focus from the current cell is necessary for a correct behavior of the Grid.
setBlur(true);
return null;
}
<Input
value={make_date_string(row.date)}
onChange={onFieldChange.bind(this, row.id, "date")}
focus={focus}
/> |
No, there are still problems... Namely in the |
Hi @avalanche1 |
hi! import {produce} from "immer";
export function CrusherEntryTable({data}) {
const [rows, setRows] = useState(data);
const [blurState, setBlur] = useState(false);
const [columns] = useState([
{
id: "date",
title: "Date",
value: (row, {focus}) => {
return (
<Input
value={row.date}
// value={handle_date_string(row.date)}
/*Binding is nec. for onFieldChange to be able to see the 3rd arg
- 'value'*/
onChange={onFieldChange.bind(this, row.id, "date")}
focus={focus}
/>
);
},
},
]);
const result = (
<>
<button onClick={add_row}>Add row</button>
<input onChange={onFieldChange} />
<Grid
rows={rows}
columns={columns}
focusOnSingleClick
// columnWidthValues={{date: 70}}
getRowKey={(row) => row.id}
blurCurrentFocus={blurState}
isColumnsResizable={true}
/>
</>
);
function onFieldChange(rowId, field, value) {
// Change a value of a field
debugger;
rows[rowId][field] = value;
setRows([].concat(rows));
// Blurring focus from the current cell is necessary for a correct behavior of the Grid.
setBlur(true);
return null;
}
function add_row() {
const newRowState = produce(rows, (draft) => {
draft.push({
id: "11",
date: "",
group: "",
advent: "",
equipment: "",
downtimeInfo: "",
timeOffOn: "",
minutesOff: "",
});
return draft;
});
setRows(newRowState);
return null;
}
return result;
} Also note, that I've created a special debugging input above the |
Hey @avalanche1 Although, I suggest to use this implementation instead of binding const onFieldChange = (rowId, field) => (value) => {
rows[rowId][field] = value;
setRows([].concat(rows))
// ...
}
const getColumns = () => {
return [
{
value: (row, { focus }) => {
return (
<Input
// we're not using bind here
onChange={onFieldChange(row.id, 'firstName')}
/>
);
},
]
} |
That project was eventually abandoned, so cannot comment on the specific problem now. |
Hi @avalanche1 |
How can I use this awesome lib with react hooks?
I'm stuck with
onFieldChange
:The text was updated successfully, but these errors were encountered: