ajax.reload()

ajax.reload()

Alexandr45Alexandr45 Posts: 19Questions: 1Answers: 2

ajax.reload() when the form is open resets the current field "select2" values to the default values

This question has an accepted answers - jump to answer

Answers

  • rf1234rf1234 Posts: 1,444Questions: 50Answers: 195

    Yes, I think that is what it is supposed to do. Why are you doing an ajax reload while the user edits data?

  • Alexandr45Alexandr45 Posts: 19Questions: 1Answers: 2

    I agree, but if this happens through setInterval

  • colincolin Posts: 8,661Questions: 0Answers: 1,449

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • rf1234rf1234 Posts: 1,444Questions: 50Answers: 195
    Answer ✓

    " ... but if this happens through setInterval" ... then you can turn it off on "open" of the form and turn it back on on "close" of the form.
    https://editor.datatables.net/reference/event/open
    https://editor.datatables.net/reference/event/closed
    https://editor.datatables.net/reference/event/close
    How to stop the interval execution:
    https://www.bitdegree.org/learn/javascript-setinterval#stopping

  • Alexandr45Alexandr45 Posts: 19Questions: 1Answers: 2

    rf1234, thank you very much

  • Alexandr45Alexandr45 Posts: 19Questions: 1Answers: 2
    edited April 8

    The working code that Roland helped me with

    var timeinter; //global variable
    
    //only start refreshing after the data table has been fully initialized
    table.on ('init', function () {
        timeinter = setInterval( function () {
              table.ajax.reload();
        }, 60000 );
    });
    
    editor.on( 'open', function () {
        clearInterval(timeinter);
    });
    
    editor.on( 'close', function () {
         timeinter = setInterval( function () {
                table.ajax.reload();
          }, 60000 );
    });
    
Sign In or Register to comment.