Detect if origin of call came from reload inside .on('processing.dt', (e, settings, processing)

Detect if origin of call came from reload inside .on('processing.dt', (e, settings, processing)

asdfUserasdfUser Posts: 1Questions: 1Answers: 0
edited November 2023 in Free community support

Is there a way to detect from the call stack if the preceding call originated from the initial loading of the data table or when the reload event (.DataTable().ajax.reload(null, false)) is fired?

I have a processing event (.on('processing.dt', function (e, settings, processing) {}) in place which runs as expected on initial loading. However, I'd like to perform some conditioning within this event, but only when the reload occurs. Are there any properties I can condition on when a reload occurs?

.on('processing.dt', function (e, settings, processing) {      
        if (processing) {

        } else {

        }
});

Answers

  • rf1234rf1234 Posts: 2,991Questions: 87Answers: 421
    edited November 2023

    A global variable should work.

    var reload = false;
    
    table
        .on('processing', function (e, settings, processing) {     
            if (processing && reload) {
             
            } else if (processing) {
     
            } else {
    
            }
            reload = false;
        });
    
    if (condition requiring a reload) {
        reload = true;
        table.ajax.reload(null, false);
    }
    
  • kthorngrenkthorngren Posts: 21,336Questions: 26Answers: 4,951

    I don't believe there is anything that indicates what process invoked the processing event. It could be anything from an ajax load/reload, sorting, paging or searching the table. I took a brief look at the settings object passed into processing but didn't see anything useful. I may have missed it though :smile:

    Probably the easiest thing to do is to use a glabal variable flag that you set when using ajax.reload() then reset at the end of the processing event.

    Kevin

Sign In or Register to comment.