Loading ...
Sorry, an error occurred while loading the content.

Re: Refreshing DataTable Content dynamically on timely basis

Expand Messages
  • sisodia_swati
    Thanks a ton Satyam. My code worked as it never had any bug. U made my day. :) Thanks for all the illustrations also. Swati. ... 24/11/2008 14:36
    Message 1 of 5 , Nov 27, 2008
    View Source
    • 0 Attachment
      Thanks a ton Satyam.
      My code worked as it never had any bug.
      U made my day. :)
      Thanks for all the illustrations also.
      Swati.

      --- In ydn-javascript@yahoogroups.com, Satyam <satyam@...> wrote:
      >
      > I meant to the argument of the DataSource constructor, sorry about the
      > confusion.
      >
      > var myDataSource = new YAHOO.util.DataSource("alert.xml?");
      >
      > Now that I'm looking at it, there is something else wrong:
      >
      > myDataSource.setInterval(15000 , myDataSource ,{
      > success : this.onDataReturnInitializeTable,
      > failure : this.onDataReturnSetRows
      > scope : myDataTable
      > });
      >
      > This is not correct, the following is:
      >
      > myDataSource.setInterval(15000 , "",{
      > success : this.myDataTable.onDataReturnInitializeTable,
      > failure : this.myDataTable.onDataReturnSetRows
      > scope : this.myDataTable
      > });
      >
      > You see, the references to onDataReturnInitializeTable and the other
      > callback are resolved when you call setInterval and the arguments get
      > evaluated. Those references are not resolved when the callbacks are
      > called, which is probably what you assumed, but when setInterval is
      > called. Also, myDataTable you put it under the scope of 'this', which
      > I'm not sure it is worth it, you might better drop those 'this' from
      > myDataTable, as you have with myDataSource. If you drop the 'this'
      > preceding myDataTable, remember putting the 'var' instruction in front
      > the first time around, just as with myDataSource.
      >
      > Satyam
      >
      >
      > sisodia_swati wrote:
      > > Thanks for the reply Satyam.
      > > I tried changing the second argument of setInterval function with a
      > > blank string:
      > >
      > > myDataSource.setInterval(15000 , "" ,{
      > > success : this.onDataReturnInitializeTable,
      > > failure : this.onDataReturnSetRows,
      > > scope : myDataTable
      > > });
      > >
      > > But this also does not seem to work, my DataTable is not refreshing.
      > > As you said, "Do always append the query mark to the DataSource
      > > constructor.".. can u please give a sample code for it? (me, being a
      > > newbie in JavaScript :P )
      > >
      > > I hope setInterval is the correct function to fulfill my purpose..or
      > > shall i use sendRequest(). If yes, how can I call it on timely basis?
      > >
      > > Thanks again,
      > > Swati.
      > >
      > > --- In ydn-javascript@yahoogroups.com, Satyam <satyam@> wrote:
      > >
      > >> Your code looks good except for the second argument to setInterval.
      > >> Normally it would be an argument much like the initialRequest
      > >> configuration attribute of the DataTable or the first argument of
      > >> DataSource sendRequest, that is, an URL-encoded string of extra
      > >> arguments to send to the server along the request. You are not
      > >>
      > > using it
      > >
      > >> and and empty string will do. In this case, by giving it
      > >>
      > > myDataSource
      > >
      > >> as an argument, it is appending the result of calling
      > >> myDataSource.toString(). This would normally be of no consequence
      > >>
      > > if
      > >
      > >> you had appended a query mark to alert.xml because then this string
      > >> would be a URL argument, which is meaningless in this case, but my
      > >> omitting that query mark you are producing an URL such as
      > >> "alert.xmlDataSource Instance (0).... " or some such and it won't
      > >>
      > > find
      > >
      > >> that file. Do always append the query mark to the DataSource
      > >> constructor. Even then, aggressive caching on the part of the
      > >>
      > > browser
      > >
      > >> might make the browser ignore your changes.
      > >>
      > >> Satyam
      > >>
      > >>
      > >> sisodia_swati wrote:
      > >>
      > >>> Hello All,
      > >>>
      > >>> I am new to Yahoo User Interface API. I am working on DataTable
      > >>> representation of my data, which I want to refresh in every 15
      > >>> seconds to let it reflect the current data from the server always.
      > >>>
      > >>> The data will be queried from the Database and will be rendered
      > >>>
      > > in
      > >
      > >>> the form of an XML document. What I need to do is, update the
      > >>> DataTable content with the latest data retrieved. Right now, I am
      > >>> working with a hard coded XML (alert.xml), which I change
      > >>>
      > > manually
      > >
      > >>> and expect the change to be reflected in the DataTable. Moreover,
      > >>>
      > > I
      > >
      > >>> want just the DataTable to refresh, not the complete page refresh.
      > >>> Below is the code I am using to resolve my purpose:
      > >>>
      > >>> YAHOO.util.Event.addListener(window, "load", function() {
      > >>>
      > >>> YAHOO.example.XHR_XML = function() {
      > >>> var formatUrl = function(elCell, oRecord, oColumn, sData)
      > >>>
      > > {
      > >
      > >>> elCell.innerHTML = "<a href='" + oRecord.getData
      > >>>
      > > ("Name")
      > >
      > >>> + "' target='_blank'>" + sData + "</a>";
      > >>> };
      > >>>
      > >>>
      > >>> var myColumnDefs = [
      > >>> {key:"Name", label:"Names", sortable:true,
      > >>> formatter:formatUrl,resizeable:true,width:'null'},
      > >>> {key:"Message",
      > >>> label:"Message",sortable:true,resizeable:true,width:'null'},
      > >>> {key:"Wait",
      > >>> label:"Wait",sortable:true,resizeable:true,width:'null'},
      > >>> {key:"Holding", label:"Holding",
      > >>> sortable:true,resizeable:true,width:'null'}
      > >>> ];
      > >>>
      > >>>
      > >>> var myDataSource = new YAHOO.util.DataSource("alert.xml");
      > >>>
      > >>> myDataSource.responseType =
      > >>>
      > > YAHOO.util.DataSource.TYPE_XML;
      > >
      > >>> myDataSource.responseSchema = {
      > >>> resultNode: "Alert",
      > >>> fields: ["Name","Message",
      > >>> {key:"Wait",parser:"number"},"Holding","MessageType"]
      > >>> };
      > >>>
      > >>> this.myDataTable = new YAHOO.widget.DataTable
      > >>>
      > > ("alertArea",
      > >
      > >>> myColumnDefs, myDataSource );
      > >>>
      > >>>
      > >>> // Subscribe to events for row selection
      > >>> this.myDataTable.subscribe("rowMouseoverEvent",
      > >>> this.myDataTable.onEventHighlightRow);
      > >>> this.myDataTable.subscribe("rowMouseoutEvent",
      > >>> this.myDataTable.onEventUnhighlightRow);
      > >>>
      > >>>
      > >>> myDataSource.setInterval(15000 , myDataSource ,{
      > >>> success : this.onDataReturnInitializeTable,
      > >>> failure : this.onDataReturnSetRows
      > >>> scope : myDataTable
      > >>> });
      > >>>
      > >>> return {
      > >>> oDS: myDataSource,
      > >>> oDT: myDataTable
      > >>> };
      > >>>
      > >>> }();
      > >>> });
      > >>>
      > >>>
      > >>> I am making use of the method setInterval(), hope this is the
      > >>>
      > > right
      > >
      > >>> direction. Please correct me if I have messed up at some place.
      > >>>
      > >>>
      > >>> ------------------------------------
      > >>>
      > >>> Yahoo! Groups Links
      > >>>
      > >>>
      > >>>
      > >>> ------------------------------------------------------------------
      > >>>
      > > ------
      > >
      > >>> No virus found in this incoming message.
      > >>> Checked by AVG - http://www.avg.com
      > >>> Version: 8.0.175 / Virus Database: 270.9.9/1807 - Release Date:
      > >>>
      > > 23/11/2008 10:59
      > >
      > >>>
      > >
      > >
      > >
      > > ------------------------------------
      > >
      > > Yahoo! Groups Links
      > >
      > >
      > >
      > >
      ------------------------------------------------------------------------
      > >
      > >
      > > No virus found in this incoming message.
      > > Checked by AVG - http://www.avg.com
      > > Version: 8.0.175 / Virus Database: 270.9.10/1810 - Release Date:
      24/11/2008 14:36
      > >
      > >
      >
    Your message has been successfully submitted and would be delivered to recipients shortly.