bryntum / support

An issues-only repository for the Bryntum project management component suite which includes powerful Grid, Scheduler, Calendar, Kanban Task Board and Gantt chart components all built in pure JS / CSS / TypeScript
https://www.bryntum.com
54 stars 6 forks source link

AjaxStore events which contain `url` should read back the `url` property so that handlers can mutate it #9781

Closed ExtAnimal closed 2 months ago

ExtAnimal commented 3 months ago

Forum post

Hi Team, We have a store configured with all the required urls' this url has a string which has to be replaced before every request with a global variable we are storing

I was listening to the beforeRequest & beforeLoad events to set replace the readUrl string with the actual selected ID like below:

this.readUrl=this.readUrl.replace('delId',PJTUtil.selectedDeliverableId);

while debugging the source code i can see that the readURL is having the updated after replacing string in above line But when the request goes to the server i dont see that replace happening its taking the delId string in the url which is causing REST error.

could you pls help me with this

const store= new AjaxStore({
    modelClass: model,
    id: 'store',
    autoLoad:false,
    listeners: {
        afterRequest ( source, params) {
            debugger;
            this.data=source.json.items;
        },
        beforeLoad({source, params}){
            this.readUrl=this.readUrl.replace('delId',selId);
        },
        beforeRequest({ source, params, body, action }){

        this.readUrl=this.readUrl.replace('delId',selId);
    },
},
readUrl: sample/delId/child/sample1?totalResults=true&limit=500",
useRestfulMethods : true,
httpMethods : {
    create:'POST',
    update : 'PATCH',
    delete : 'DELETE'
},
createUrl: sample/delId/child/sample1",
deleteUrl: sample/delId/child/sample1",
updateUrl: sample/delId/child/sample1",
headers: {
    'Authorization': sample.authorization,
        'Content-Type': 'application/json',
        'Accept-Language': sample.faLocale,
        'Access-Control-Allow-Methods': 'GET, POST, OPTIONS'
}
});

the above is a representation of our store code

and we are loading the store like this

await store.load()

even after changing the readURL in the beforeLoad & beforeRequest, the request url which actually gets executed is the readURL which is configured to the store

expectation : sample/111111111/child/sample1?totalResults=true&limit=500", current behaviour : sample/delId/child/sample1?totalResults=true&limit=500", (this is wrong it throws the REST error)