Skip to content
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

Inline cell editing #610

Open
mikkurogue opened this issue Jun 26, 2024 · 4 comments
Open

Inline cell editing #610

mikkurogue opened this issue Jun 26, 2024 · 4 comments

Comments

@mikkurogue
Copy link

mikkurogue commented Jun 26, 2024

In our implementation, we want to be able to add records to the array inline from the datatable, think of a structure of the table and at the bottom an "empty" row that works as a button that adds a new entry to the records. The way we do this now is that we use an unstyled button and use a transparent styling to indicate "interactivity".

However, what we can't yet do or figure out is inline cell value editing. I understand we can handle cell clicks but I'd rather make it that we can focus on the cell and have an input in them and then "save" the value to the records array once we unfocus the input

Some pseudo code to kind of illustrate what I mean

const records = [{name: 'row 1', some_val: 100}, {name: 'row2', some_val: 101}];

const create = () => {
    // push an "empty" record, or a default variant of a record
    records.push({name: '', some_val: 0})
}

// cellEdit are pseudo props - does not exist
<DataTable columns={table_columns} records={records} cellEditable />
<Button color="rgba(173, 173, 173, 1)" variant="transparent" onClick={create}>New record...</Button>

What would be recommended way of doing this?

I apologize before hand if there is already an issue or fix for this but after searching I can't seem to find a relevant issue or article in docs.

@mikkurogue
Copy link
Author

I did find this: https://icflorescu.github.io/mantine-datatable/examples/expanding-rows/#using-collapse-function-in-row-expansion-content

However I think for our use-case this would be a bit too "verbose" as we want to edit directly in the cell.

@mikkurogue
Copy link
Author

Current workaround is to define the render prop in the column to render an unstyled input. Not sure if I'm a big fan but for now this "works". I'll keep this open for now still for discussion in case we may want to look into supporting cell editing.

@icflorescu its your call :)

@planecore
Copy link

Did you manage to do proper cell editing?

@mikkurogue
Copy link
Author

Not necessarily, I havent yet had the time to fork and implement something myself. The way I eventually solved it was by using cell click handlers to "replace" the cell with an input and then when listen to the leave focus event to then save the value in the dataset and re-render the row

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants