feat: new rows created with filter data as initial value

This commit is contained in:
shams mosowi
2019-11-11 15:08:10 +11:00
parent 14279335a6
commit 616566d0ab
3 changed files with 17 additions and 5 deletions

View File

@@ -14,7 +14,6 @@ const Grid = (props: any) => {
columns,
RowRenderer,
handleRowGetter,
tableHeight,
onGridRowsUpdated,
rows,

View File

@@ -221,7 +221,7 @@ function Table(props: Props) {
return (
<Button
onClick={() => {
tableActions.row.add();
addRow();
}}
>
Add a new row
@@ -241,6 +241,19 @@ function Table(props: Props) {
}
return rows[index];
};
const addRow = (data?: any) => {
if (filters) {
// adds filter data into the new row
const filtersData = filters.reduce(
(accumulator: any, currentValue: FireTableFilter) => ({
...accumulator,
[currentValue.key]: currentValue.value,
}),
{}
);
tableActions.row.add({ ...filtersData, ...data });
} else tableActions.row.add({ ...data });
};
return (
<>
<Suspense fallback={<div>Loading header...</div>}>
@@ -251,7 +264,7 @@ function Table(props: Props) {
updateConfig={tableActions.table.updateConfig}
columns={columns}
filters={filters}
addRow={tableActions.row.add}
addRow={addRow}
/>
</Suspense>{" "}
{!tableState.loadingColumns ? (
@@ -267,7 +280,7 @@ function Table(props: Props) {
rows={rows}
resizeColumn={tableActions.column.resize}
loadingRows={tableState.loadingRows}
addRow={tableActions.row.add}
addRow={addRow}
setSelectedCell={setSelectedCell}
/>
) : (

View File

@@ -16,7 +16,7 @@ export default function TableView() {
// encoded
//%5B%7B%20key:%20%22cohort%22,%20operator:%20%22==%22,%20value:%20%22SYD1%22%20%7D%5D
// decoded
//[{ key: "cohort", operator: "==", value: "AMS1" }]
//[{key:"cohort",operator:"==",value:"AMS1"}]
console.log(parsed.filters);
filters = eval(parsed.filters);
}