开发者

Updating Cells One After Another With Break From Database

I have a Excel like online spreadsheet for some purpose and it's almost done and working perfect but there is a issue I am facin开发者_Python百科g and want to rectify.

You can see spreadsheet there at http://partydesigners.site50.net/Excel%20Like%20App/Index.html

The issue is that at one single time more than 1 users are using this spreadsheet and if one person modify any cell the other don't get it updated in their spreadsheet so I planned to have a setTimeout() function to call a function that will update every cell in sheet there from database. '

Now the problem is there are 40 rows each having 10 records from the database and 400 records needs to be updated every "n" seconds so it hangs the browser and UE suffers. I thought I can create a timer like update one cell and then move to another after few seconds and then update another after few seconds in a chain.

You can imagine as I updated first cell and then when it will be finished updating it will call a function for a cell next to it and so on a continue chain.

So what pseudo-jquery code you would write for it?


As Jonathun Kuhn mentioned in the comments, it would be better to keep track of only the cells that need to be changed and update them accordingly

Depending on how you have this setup with your database, will depend on how to keep track of what has been changed. But my first thought is to have a table that keeps track of one change per row along with a timestamp of when the change happened. Then you can run a function from the browser every 'n' seconds that uses some ajax to request all changes since it's last request (can keep track of the unique id of the last update, sort by timestamp and grab everything new).

This should help speed things up as it will only spend time updating cells that actually need it.

As a disclaimer, however, it is still very possible that a second user updates a cell before the first edit has shown on their screen. (Think two users editing a cell at virtually the same time, maybe the second initiates a 'save' milliseconds after the first.) The best way I can think of handling this is to show a warning to the second user, if it is noticed that they are editing something very quickly after a previous edit, that they may be overwriting data.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜