Open nmih opened 8 months ago
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
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.
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.
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 https://github.com/olifolkerd/tabulator/issues/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.
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!
FYI I decided to implement this and opened up a PR https://github.com/olifolkerd/tabulator/pull/4485
This would be really great to have, it would enable a workaround I have for https://github.com/olifolkerd/tabulator/issues/4398 as well which I will post in that thread.
@olifolkerd
I'm facing the same issue and I'd like to connect to this and mark the topic a bug straight up. It should be normal if you call a setValue on a cell object from code then logic sets its flag to "edited" instantly and automatically. Imo there is no need for additional wrapper code call to set it manually afterwards.
A value change is a value change. If value != initialValue
that is clearly an "edited" case no matter how it got to this state. I really dislike the idea of "If you are programmatically changing the value of the cell then you already know you have updated it in your code.". Table logic should be in scope to keep track not the wrapper code.
For temporary solution @nmih 's PR would do great, otherwise in all my previous table implementations code setValues triggered an "edited" flag set.
@mormitech thanks for your additional feedback.
This is very much a new feature, a bug is when something does not operate inline with the documentation, which this feature very much does.
It is on the to-do list and will be considered for a future update
Cheers
Oli
@olifolkerd Got it, thanks.
Alternative suggestion: introduce a "changed" flag next to the "edited". When setValue called from code: "changed" flag is set to true, when user interaction changes the cell's value: "edited" is set to true.
I also have stumbled upon this use case. Any updates ?
Waiting for the new feature. Currently cell.setValue() not trigger cellEdited.
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
cell.setEdited()
orcell.markEdited()
to mirrorcell.clearEdited()
table.setCellEdited([cell1, cell2])
to mirrortable.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.