Click here to Skip to main content
16,019,983 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to implement a dashboard page which has like 4 widgets on it. All  4 widgets will belong to a different category and will display recent updates and changes on that category. How should i proceed keeping in mind the database end..should i define triggers on my table for the purpose if any insert / update happens on the table i copy them to my tables and display them inside a widget? Thanks.
Posted
Comments
R. Giskard Reventlov 13-Jun-11 9:04am    
What research have you already done? What have you already tried?
adnan_1985 14-Jun-11 2:27am    
I just though of an hazy idea that i would write update triggers on the tables when update or insert happens. I know this is stupid but still planning out.

If it were me, I'd use either a timer object or a thread that started in widget was created, and in the widget, query the database every minute or so. If the data changed, have the widget update itself.
 
Share this answer
 
Comments
BobJanova 13-Jun-11 10:39am    
It's tagged ASP.net, so I'm imagining this to be a web app and therefore the widgets (in the user's browser) can't directly see the data source.
#realJSOP 14-Jun-11 5:52am    
But there's no reason they can't be coded to see the data source. In fact, if they were coded to do their own updates, the site would be a) more modular, and b) more maintainable
adnan_1985 14-Jun-11 1:20am    
yes it's a webapp. Thanks for the response
The important point with web applications is that all updates are driven by the client. HTTP is stateless and operates on a model with clients asking for information and servers providing it.

So in your client code, you will need to have an AJAX request that asks for updates to the widgets. To save on traffic you could ask for updates to all four. The callback for that request should parse the server response and make appropriate adjustments to the widget display.

On the server, you need an easy way of determining whether a table has changed since a particular time. How exactly you do this depends on what the widgets and the data storage is, but it should be fast (i.e. no complex queries). When I did something similar (a PM box which updated its display when you received a message) the table I was using had an auto_increment key and the client code used the largest ID it had seen as the request token. A query like select id from pm where id>@clientrequestid or select id from pm order by id desc limit 1 will do the job of telling you whether there are updates and not hit the database hard; if there are updates, you can then do a more complex query to retrieve the data the client will need to render the update.
 
Share this answer
 
There is only one way to check for update when it comes to browser and web server, which is polling. You can do this using window.setTimeout (initiate AJAX request from client) or you can have timer on your page.

For better performance you should implement AJAX on your page when you are polling for data.

When call goes to backend check database for update and update the widgets with new content.

The Websocket API in HTML-5 provides better architecture to handle this kind of situation. Where server notify client (browser) for any changes. But I thing it if far from your actual requirement.

But for now polling is the best way to implement this kind of requirement.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900