Hi,
I am building a web-app that allows several users to perform read and write-operations on the same table. What is the smartest way of preventing that a record in the table is simultaneously edited by different users (ie. changes from user A get overwritten by user B without any of users noticing the conflicting behaviour)?
Thanks!
C
Hello,
I have not tested this scenario before.
I'll let you know after some research on jqgrid available events.
If you can limit with dialog editing, you can use following events of edit dialogs.
afterShowForm and onClose. You can make a custom ajax call in JS function to set lock field of edited row id.
Plus, you need to set "rowactions"=>false to disable inline editing.
Demo usage here: https://gist.github.com/gridphp/a8598a323d7e06ed53a5a897b7c58f64
Abu,
I am writing an application which will be used by multiple users and am considering how to use database locks. Can you clarify the nature of this function in your above example?:
jQuery(document).data(‘lock_rowid’,rowid);
Is lock_rowid a custom function which needs to be written? This looks like it’s a lock on the front-end with the GUI rather than at the database level. Is that correct?
Thanks
– pcatt
Yes, that’s correct. It’s Client side locking solution. For server side, you need to introduce a field of locked with that item.
jQuery(document).data('lock_rowid',rowid);
Above code is a jQuery solution of a JS global variable which is available everywhere in JS code. So we set it when dialog is opened and unset when it’s closed.
Demo does not show how to apply this limitation when opening edit dialog.
I’ve updated demo to have this as well.
https://gist.github.com/gridphp/a8598a323d7e06ed53a5a897b7c58f64 (line 30-55)
You need to put custom ajax calls to check on server if that rowid is locked or not.
Let me know in case of further queries.