George Pligoropoulos
George Pligoropoulos

Reputation: 2939

How to abort / cancel the loading operation of a store in Sencha ExtJS v6?

I have used these two sources below:

but none of them is valid in the version 6 of extjs

How could I cancel the load operation every time a new operation starts?

Upvotes: 2

Views: 3162

Answers (2)

Thomas Lauria
Thomas Lauria

Reputation: 908

I assume that the underlying proxy in the store is a AJAX based proxy. In that case a simple

store.getProxy().abort();

should do the job.

Upvotes: 1

George Pligoropoulos
George Pligoropoulos

Reputation: 2939

In version 6.0.2 of ExtJS some things have changed and the Operation class has and abort method

There is no getOperation method but there is the beforeload which is useful to grab the operation.

By collecting one or more operations you can safely abort them before starting a new operation.

The following Typescript class will be of help:

module ext_ts {
interface Abortable {
    abort(): void
}

export class AutoAbortPreviousOperation {
    private _storeOperations: Array<Abortable> = []

    applyOnStore(store): any {
        let me = this

        return store.on({
            destroyable: true,
            beforeload: function (theStore, operation, eOpts) {
                let lastOperation = me._storeOperations.pop()

                if (lastOperation) {
                    console.log("aborting previous operation safely")

                    lastOperation.abort()   //this abort is safe so no need to check !lastOperation.isComplete()
                } else {
                    //nop
                }

                me._storeOperations.push(operation)    //add this operation for later usage

                return true //let the loading begin
            }
        })
    }
}
}

Note that the statusCode of a request which is forcely cancelled by the user is: -1

Useful links:

Upvotes: 2

Related Questions