We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

DataManager accepting a Promise

This applies to any component that can use the DataManager as datasource.

I have a service which returns a promise  then fetches data from a server to be resolved later.

I want to create a new adaptor which returns a promise to the data manager.

Does the datamanager support receiving promises from its adaptor?



5 Replies

TS Thavasianand Sankaranarayanan Syncfusion Team September 24, 2019 11:45 AM UTC

Hi Customer, 

Greetings from Syncfusion support. 

Based on your query, we suspect that you want to create a own adaptor which returns a promise to the data manager. We have already discussed about your requirement in our documentation. Please find the below documentation link for more information. 


Regards, 
Thavasianand S. 



ZQ z q September 24, 2019 10:00 PM UTC

I have looked at https://ej2.syncfusion.com/javascript/documentation/grid/data-binding/#custom-adaptor 

but in processQuery()

I dont see where you can return a Promise to processQuery() does processQuery() accept a Promise?

I tested it again. Within the processQuery() method I returned a new promise. ProcessResponse was immediately called. 


public processQuery(dataManager: DataManager, query: Query): Object {
const def = new Deferred();

this.service.getList(this.collectionFilterParamsInput)
.then((result) => {
def.resolve({ result: result.slice(0, 50), count: 50 });
}).catch((error) => {
def.reject({ result: [], count: 0 });
});

return def.promise;
}




TS Thavasianand Sankaranarayanan Syncfusion Team September 25, 2019 11:47 AM UTC

Hi Customer, 

ProcessQuery: ProcessQuery is used to convert the query in property format(syntax) based on its adaptor. Also it send the request to the server. 

 

ProcessResponse: If the request gets success it returns the data(from server) to the processResponse method based on your query processing. Please refer the below screenshot and refer the below documentation link for more information. 

 


Regards, 
Thavasianand S. 



FA Faruk January 8, 2020 03:41 PM UTC

For anyone else that might be looking into this. To handle Async calls you will have to do that request in makeRequest method of your custom adapter. As you can see defferred is passed in. 

If you look at manager.js code you will see that executeQuery  checks if adaptor has `makeRequest`  defined and if so it calls it with `(result, deffered, args, query)`
if (!this.dataSource.offline && (this.dataSource.url !== undefined && this.dataSource.url !== '')
|| (!isNullOrUndefined(this.adaptor[makeRequest]))) {
var result = this.adaptor.processQuery(this, query);
if (!isNullOrUndefined(this.adaptor[makeRequest])) {
this.adaptor[makeRequest](result, deffered, args, query);
}
else if (!isNullOrUndefined(result.url)) {
this.makeRequest(result, deffered, args, query);
}
else {
args = DataManager.getDeferedArgs(query, result, args);
deffered.resolve(args);
}
}
else {
DataManager.nextTick(function () {
var res = _this.executeLocal(query);
args = DataManager.getDeferedArgs(query, res, args);
deffered.resolve(args);
});
}
if (done || fail) {
deffered.promise.then(done, fail);
}
if (always) {
deffered.promise.then(always, always);
}
return deffered.promise;


DR Dhivya Rajendran Syncfusion Team January 9, 2020 01:03 PM UTC

Hi Faruk, 

Yes, We have send the post to the server through an makeRequest method. Please share us on what you are expecting to achieve and tell us in which way you are going to customize. 

Regards,
R. Dhivya 


Loader.
Live Chat Icon For mobile
Up arrow icon