I'm using a product called DHTMLXGrid, which is a JS library for creating spreadsheet-like tables on a web page.
When I edit a cell, and then click outside the cell, an event is fired (they call it onCellEdit) and I do stuff to handle that event - an AJAX call to save the cell data to the DB.
But if the user edits a cell and clicks a button outside the grid that triggers some other JavaScript, the onCellEdit handler doesn't get chance to run before the new JS code runs. Without going into the details, this messes things up.
So I have the "Grid code" and the "Button code" and I want the Button code to wait till the Grid code is done.
So I tried inserting a silly sleep() method at the start of the Button code run. My erroneous thinking was that this would give the Grid code a chance to run. But that assumes multi-threading which of course we don't have. The result was that all JS code execution was held up, and my Button code still got executed before the Grid code.
So the general problem is that clicking a button removes focus from the previously selected element. Both the click and the change/blur are events. I want the blur event to be handled before the click event. The opposite seems to happen. I'm assuming that in pure JS it would work this way (I haven't tried it), but this is a complex library that does it's own thing.
Bottom line - is there a way I can asynchronously pause my Button code to allow my Grid code to complete, then proceed with the Button code?
Thanks,
Paul