multi-user concurrent system editing
multi-user concurrent system editing
The latest project I'm building with Editor will be multi-user. I started thinking about locking and multi-user concurrency and found discussions at https://datatables.net/forums/discussion/15828 and https://datatables.net/forums/discussion/comment/127493/#Comment_127493.
The one point which is not made in either of these is that the default editor fields in an edit form are filled from the table entry which was loaded to the browser some time ago. If the table is browser based, the data is loaded at the time the page first loads. Even if the table is server based, the data is loaded when the page is loaded. These could be sitting there for a while before the user decides to edit one of the rows.
I see the comment in this post about server-side events. This talks about data which is being submitted being passed in the pre* event handlers.
But truly, when the edit window is opened, the data should be retrieved from the server at that time, to minimize the risk of using old data. I believe https://editor.datatables.net/reference/event/initEdit must be used in this situation, following logic similar to that which is under "Ajax call to lock this row". The new logic would retrieve the current data from the server, and in the success handler apply returned data to the form.
Am I getting this right?
Should there be, or is there, a more "off the shelf" solution to this?
This question has an accepted answers - jump to answer
Answers
"Should there be, or is there, a more "off the shelf" solution to this?"
I think there definitely should be an "off the shelf" solution for this. But I am not aware of any ...
@allan, @colin could you update us on this please.
I've actually got exactly this topic noted down to write up as a blog post. I'll try to get it done next week, but I've got a few other things (accounts...) that need to be dealt with next week as well.
Allan
Hi @allan - understand you're busy and didn't get to the blog last week. Any guidance on the topic in the interim? -thanks
Sorry - yes. Basically what you need to do is use a custom button rather then
edit
(or similar). Have that button's action make an Ajax call to the server to get the latest data for the selected row and draw that into the table usingrow().data()
. Finally, useedit()
to trigger editing on that row (which is basically alledit
does anyway).Allan
Finally circling back to this. Thanks for https://datatables.net/blog/2019-04-15 -- this looks great. One question: In
editRefresh()
, is there a reason you left outaction
key in the data sent to the server? Mypost
handler is currently looking foraction
, and it'd be convenient to see'refresh'
there. I know right now I can update my version ofeditRefresh()
, but if you make this part of a future release, my code would be future-safe.UPDATE: hmm, maybe I'm mistaken -- I guess the action is sent outside of the data? So will the action be 'edit' in this case?
Sorry for the stream of consciousness here, but yes it looks like I have to add 'action' to the "form" which is being sent.
But now I'm stuck at the call to
.ids()
, which returns undefined for me. I suspect (without evidence) this is because I use 'idSrc` option. Will try to recreate for easier debug.bleh - having trouble just reproducing your example from the blog. I'm not sure I can get there. see http://live.datatables.net/sozuroqo/1/edit
one clue is I'm using jquery, and noticed rows().ids() is handled within jquery.dataTables.js. Still debugging but trying to capture what I've done so far.
Ah yes, that's the culprit. rowIdFn returns data[mSource] and mSource is 'DT_RowId', but DT_RowId is not defined within my data.
This is also within jquery.dataTables.js.
Any suggestions for a workaround? I'm kinda stuck at this point.
Ah. Oops. Seems like I haven't been setting the rowId dataTables option. Interesting that this hasn't caused any problems until now, as I've been using the package for years.
Thanks for your patience.
That would do it - great to hear you've got it working now .
Allan
There were some tweaks required to the code published in https://datatables.net/blog/2019-04-15, some generic some because of my application requirements. Should I also post this on the blog entry?
See comments on lines 25 and 36 in particular, but you might also consider line 17 when you bring this into the standard offering.
...almost forgot about line 13, also modified because I have different url's for the various ajax calls
All good points - thanks! Yes, if you would be happy to post that across on the blog that would be great. And yes, they do need to be considered when including in the main library.
Allan
Thanks, done. Although I posted when I was trying to hit preview, so it's a little abrupt.
One last question (I hope). On line 37 above, is there any generic way to find the current editor instance? The code I posted expects the editor instance to be in a specific global variable.
Not really. You can use
editor()
to get an Editor instance that is assigned to a DataTable, but the issue there is that multiple instances could actually be assigned.However, you can in this case just use
config.editor
inside the button's event handler since it is extendingedit
and that has aeditor
property that gets assigned to the Editor instance the button is controlling.Allan