- Home
- Forum
- Angular - EJ 2
- OdataV4Adapter Search command on Asp.Net Core Odata V7.1
OdataV4Adapter Search command on Asp.Net Core Odata V7.1
Hi,
I found out that Asp.Net Core Odata V7.1 has yet to support the $Select command yet, is it possible to replace the search command with $filter? Thank you.
SIGN IN To post a reply.
7 Replies
TS
Thavasianand Sankaranarayanan
Syncfusion Team
July 4, 2019 08:45 AM UTC
Hi Albert,
Thanks for contacting Syncfusion support.
We have analyzed your requirement. We suggest you to achieve your requirement by using the “customAdaptor” concept of EJ2 DataManager. Please refer the documentation link below for more details on custom adaptor,
Documentation : https://ej2.syncfusion.com/angular/documentation/grid/data-binding/?no-cache=1#custom-adaptor
With custom adaptor in Grid, you can override the default methods of “ODataV4Adaptor”(or any other adaptors) and customize the adaptor based on your requirement. In the below code, we have created a “customAdaptor” which is extended from ODataV4Adaptor. In this new customAdaptor class we have replaced the ‘select’ parameters with ‘$filter’.
Please refer to the code example below,
|
class CustomAdaptor extends ODataV4Adaptor {
options = {
requestType: 'get',
accept: 'application/json, text/javascript, */*; q=0.01',
multipartAccept: 'multipart/mixed',
sortBy: '$orderby',
select: '$filter', //Replaced the default $select with “$filter”
skip: '$skip',
take: '$top',
count: '$count',
search: '$search',
where: '$filter',
expand: '$expand',
batch: '$batch',
changeSet: '--changeset_',
batchPre: 'batch_',
contentId: 'Content-Id: ',
batchContent: 'Content-Type: multipart/mixed; boundary=',
changeSetContent: 'Content-Type: application/http\nContent-Transfer-Encoding: binary ',
batchChangeSetContentType: 'Content-Type: application/json; charset=utf-8 ',
updateType: 'PATCH',
localTime: false,
apply: '$apply'
};
}
|
Please get back to us if you need further assistance.
Regards,
Thavasianand S.
AK
Albert K
July 4, 2019 10:03 AM UTC
Thank you. How about Search, can I also replace it with Filter ?
TS
Thavasianand Sankaranarayanan
Syncfusion Team
July 5, 2019 06:26 AM UTC
Hi Albert,
Yes, you can also modify the search query name “$search” with “$filter”. You can modify any of the query string names provided in the options based on your requirement.
Please get back to us if you need further assistance.
Regards,
Thavasianand S.
AK
Albert K
July 8, 2019 02:46 AM UTC
Hi,
I have tried that but it does not seems to work. Meaning the asp.net server is still returning the full dataset instead of the filtered ones. What else can I do? Thank you.
TS
Thavasianand Sankaranarayanan
Syncfusion Team
July 8, 2019 12:16 PM UTC
Hi Albert,
We are sorry for the inconvenience caused.
We suggest you to provide the custom names for the search query strings by ignoring the $ symbol(provide unique names for the query strings). Please refer the code below,
|
class CustomAdaptor extends ej.data.ODataV4Adaptor {
options = {
...
search: 'filter', //Use a unique name for the search query, by ignoring the $
where: '$filter',
...
};
}
|
And also we suggest you to ensure to handle the searching/filtering operations at server side, with the received query string. You need to handle the operations at server side for filtering/searching to work.
|
[EnableQuery]
public IQueryable<Orders> Get()
{
...
var querystr = HttpContext.Current.Request.QueryString; //here you will be getting the query string. Use this querystring to handle the server side operations
...
return order.AsQueryable();
}
|
Please get back to us if you need further assistance.
Regards,
Thavasianand S.
AK
Albert K
July 9, 2019 08:38 AM UTC
Hi,
I did debug on the server side and the query string shows $count=true&$filter=John&$skip=0&$top=15 where Odata expect the filter to be $filter=name eq 'John'
In the angular i have set the search setting
this.searchSettings = {fields: ['name']};
TS
Thavasianand Sankaranarayanan
Syncfusion Team
July 10, 2019 09:51 AM UTC
Hi Albert,
We have analyzed your requirement. Based on your requirement, we would like to suggest you to override the “convertToQueryString” method of the DataManger, and use the highlighted codes in that method based on your requirement to form your own customized request url during search. You can also customize this url based on your requirement for any actions like sort/filter/search etc. Please use the code below,
class CustomAdaptor extends ODataV4Adaptor{
options = {
...
search: '$filtersearch',
where: '$filter',
...
};
public convertToQueryString(request: Object, query: Query, dm: DataManager): string { //Override the default “convertToQueryString” method
let res: string[] | string = [];
let table: string = 'table';
let tableName: string = request[table] || '';
let format: string = '$format';
delete request[table];
if (dm.dataSource.requiresFormat) {
request[format] = 'json';
}
let keys: string[] = Object.keys(request);
for (let prop of keys) {
//We have customized the request url in the below highlighted code by adding the “fieldNames”, “eq” and make the request by checking for the search query.
//You can customize the request Url by changing the below lines based on your requirement for any of your actions like sort/filter/search actions
if(prop == "$filtersearch"){
(<string[]>res).push(prop + '=' + query.queries[0].e.fieldNames[0] + 'eq' + request[prop]);
} else {
(<string[]>res).push(prop + '=' + request[prop]);
}
}
res = (<string[]>res).join('&');
if (dm.dataSource.url && dm.dataSource.url.indexOf('?') !== -1 && !tableName) {
return (<string>res);
}
return res.length ? tableName + '?' + res : tableName || '';
}
}
Please get back to us if you need further assistance.
Regards,
Thavasianand S.
SIGN IN To post a reply.
- 7 Replies
- 2 Participants
-
AK Albert K
- Jul 3, 2019 08:28 AM UTC
- Jul 10, 2019 09:51 AM UTC