is there a way for javascript to tell when a table has timed out and the table needs to be reloaded?

is there a way for javascript to tell when a table has timed out and the table needs to be reloaded?

pmarks906dpmarks906d Posts: 61Questions: 18Answers: 0
  1. I have an embedded cloudtable on my web page which I access and control using client side javascript.
  2. When the table times out it closes the display and visually indicates the page needs to be reloaded.
  3. I assume when this happens that the javascript cannot access the table until it is re-loaded. Is that assumption correct?
  4. Is there any way for javascript, through events and/or through polling, to tell when a timeout has happened and that the table needs reloaded?
  5. Also, when the table has timed out, does the whole page have to be reloaded (location.reload(true)) or is there a way for javascript to cause the table to reload without reloading the whole page?
  6. If the table reloads without reloading the whole page, do the document.addEventListener('ct-ready' ) and table.on( 'init.dt') events fire again just like when the whole page is reloaded?
    Thanks

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 62,992Questions: 1Answers: 10,367 Site admin
    Answer ✓

    I assume when this happens that the javascript cannot access the table until it is re-loaded. Is that assumption correct?

    That is the intention, yes. The idea is that the allowed session time has been timed out, so a new token is required. A refresh is necessitated for that.

    Is there any way for javascript, through events and/or through polling, to tell when a timeout has happened and that the table needs reloaded?

    Not as an API, but I guess you could poll for the element that shows the time out message and reload if that appears.

    Also, when the table has timed out, does the whole page have to be reloaded (location.reload(true)) or is there a way for javascript to cause the table to reload without reloading the whole page?

    A full reload at the moment (this is specific to CloudTable's security mechanism - it isn't a DataTables requirement).

    If the table reloads without reloading the whole page, do the document.addEventListener('ct-ready' ) and table.on( 'init.dt') events fire again just like when the whole page is reloaded?

    Yes, since it is a page load, the page load events will trigger again.

    Allan

  • pmarks906dpmarks906d Posts: 61Questions: 18Answers: 0

    Under what conditions does a table session expire? After a certain amount of time? Does the page have to be showing? not showing? closed? I'm trying to set it up so that if i come back to use one of my pages and if the table has expired then my javascript software can reload the page automatically. But I have to know how to get the table to expire to write and test the javascript.

  • allanallan Posts: 62,992Questions: 1Answers: 10,367 Site admin
    Answer ✓

    20 minutes non-usage by default.

    Allan

  • pmarks906dpmarks906d Posts: 61Questions: 18Answers: 0

    When a table has expired and needs reloading, is there a javascript call I can make on the table or its editor, some response from which will indicate that the table needs reloading? I've tried reading from a row but that doesn't fail. I tried submitting a row but I don't know what kind of object the submit() returns, and the submitcomplete event doesn't fire. Thanks.

  • pmarks906dpmarks906d Posts: 61Questions: 18Answers: 0

    SOLVED AGAIN: An embedded cloudtable is expired when it has had no connection with the server for a default of 20 minutes. The server closes the connection. So if the browser is closed and then re-opened after 20 minutes, the cloudtable will have to be re-loaded by reloading the page in order to bring the connection current. When the cloudtable is expired, the document on the client side is shown to have a div element with the class name "cloudtables__error-foreground". When the cloudtable is active this div element is not there. So if javascript is able to get a div element by that class name, then the table is expired, and location.reload(true) will have to be called to bring the connection current. Thus the following code works:

    let errorMessageElements = document.getElementsByClassName
        ("cloudtables__error-foreground");
    let errorMessageArray = 
        Array.prototype.slice.call( errorMessageElements );
    if (errorMessageArray.length > 0) {
      location.reload(true); // at least one cloudtable on the page is expired, so reload
    } else {
      // the connection is current and the cloudtable can be manipulated by javascript
    }
    
  • allanallan Posts: 62,992Questions: 1Answers: 10,367 Site admin

    That looks like a good way of doing it. Thanks for sharing that.

    When I loop back to go on with some more intensive CloudTables development I'll look at putting in an event for that.

    Allan

Sign In or Register to comment.