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

Ability to programmatically mark cell as edited #4443

Open
nmih opened this issue Mar 22, 2024 · 4 comments
Open

Ability to programmatically mark cell as edited #4443

nmih opened this issue Mar 22, 2024 · 4 comments
Labels
Suggested Feature A suggested feature that is waiting review

Comments

@nmih
Copy link

nmih commented Mar 22, 2024

Is your feature request related to a problem? Please describe.
Developers have the ability to clear a cell as edited (https://tabulator.info/docs/6.0/edit#history). However, we do not have the ability to do the opposite and mark something as edited. A similar question was raised in this Stackoverflow link.

Describe the solution you'd like

  • Add a new method on the cell component cell.setEdited() or cell.markEdited() to mirror cell.clearEdited()
  • Add a new method on the table component table.setCellEdited([cell1, cell2]) to mirror table.clearCellEdited([cell1, cell2])

Describe alternatives you've considered
Tracking programmatic cell updates (not made by the user, but rather the code) in a custom history stack seems to be the only way around this. We are also attempting to inject the programmatically edited cells into the Tabulator stack of editedCells.

Additional context
We would like our users to be able to preview a change that was made programmatically to be able to then save that change. We currently use table.getEditedCells() but this does not return cells that were changed programmatically. Adding this function would enable this functionality.

@nmih nmih added the Suggested Feature A suggested feature that is waiting review label Mar 22, 2024
@olifolkerd
Copy link
Owner

Hey,

Thanks for the suggestion.

I'm unsure why this would be needed. Cells get marked as edited when a super edits them. If they have not been edited then the flag should not be set. If you are programmatically changing the value of the cell then you already know you have updated it in your code.

Could you please clarify the usage case.

Cheers

Oli

@nmih
Copy link
Author

nmih commented Mar 22, 2024

Sure thing Oli!

I will break down our use case in a couple ways, first as a contrived example similar to the Stackoverflow question linked (which I can see us doing in the future), as well as our current use case.

I believe this boils down to us wanting to implement a table where user edits are mixed with user-triggered programmatic actions, and we want to easily use getEditedCells to retrieve the changed cells. From the perspective of the user these are all "user" edits, but from the perspective of the developer, the edits made programmatically do not get tracked as a user edit even though it was triggered by a user.

If this is not in scope of Tabulator we will definitely shift to tracking history on our own, but it is super convenient to be able to utilize the history stack, getEditedCells, other related features of Tabulator and not have to reimplement the same functionality.

Contrived example

JSFiddle: https://jsfiddle.net/nathan_mih/04fxvz7e/

In this example, the table is user editable. It also has a button "Retrieve Machine Reading" to retrieve values from some hypothetical API and set them as the data for a certain column. This acts as a preview for the user, and following this preview of data, they could then click Save to send the data back to the server.

The screengrab below shows the log of the Save button, which simply uses table.getEditedCells() and loops over the edited cells to then hypothetically send that as a payload to update the data in a database. You can see that the programmatic change is not reflected there, which is intended default behavior as you describe. However this feature request would easily enable us to track the programmatic change as a user edit.

tabulator feature req

Our current use case

We are building an interactive table that mixes per-cell user-edits with quicker tools to make those edits. I imagine we could provide similar functionality as the contrived example above to allow users to set an entire column of data using a button or input that captures the desired data the user would like to apply to that column, then applies it as an edit to multiple cells at once.

This request comes from a workaround for a solution we implemented for #4398 -- we currently are overriding the clipboardPasteAction to use cell.setValue so clipboard changes get tracked as a user edit. With this feature, we would simply be able to add cell.setEdited and our implementation needs would be very close to complete. If that feature request is something that could be worked on, this request is not as necessary (but I still do see it being useful).

--

Thanks as always for the great library and your quick responses. Let me know if I can clarify more.

@JanRomero
Copy link

I was also looking for this method today to automatically mark added rows as edited. When saving changes I collect all rows with edits and send those to the server. To include new rows I now get all rows with changes or Id 0. Maybe that makes more sense anyway, but my first instinct was to just mark a cell as edited when adding the row.

I’d like to join OP in thanking you for your work on Tabulator. A godsend!

@nmih
Copy link
Author

nmih commented Apr 27, 2024

FYI I decided to implement this and opened up a PR #4485

This would be really great to have, it would enable a workaround I have for #4398 as well which I will post in that thread.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Suggested Feature A suggested feature that is waiting review
Projects
None yet
Development

No branches or pull requests

3 participants