[Solved]How to use Contain
I'm using ”Adapters.ODataV4Adaptor”.









I want to know how to use Contain.
I expect 333, but it doesn't work.
I confirmed that "StartWith" parameter was sent. How do I send "Contain" parameter?
I have another question.
I use "Search" Toolbar.
but it doesn't work.
”Search parameter” seems to be sending.
Is there a problem with the server-side implementation?
Either way, I want to implement a search easily.
I would appreciate any advice.
SIGN IN To post a reply.
7 Replies
VN
Vignesh Natarajan
Syncfusion Team
May 11, 2020 05:57 AM UTC
Hi Nobuhide,
Greetings from Syncfusion support.
Query: “I want to know how to use Contain.”
From your query we understand that you want to change the default operator of column to “contains” from startswith. We have already documented your request in our UG documentation. Kindly refer the below link for your reference
Query: “I use "Search" Toolbar.”
We have ensured the reported issue by preparing a ODataV4 adaptor sample with online free OdataV4 service (Tripin). We are able to perform search operation in Grid without any error. For your convenience we have prepared a sample which can be downloaded from below
Kindly ensure that your ODataV4 API support $search operation. Please get back to us if you have further queries
Regards,
Vignesh Natarajan
NT
Nobuhide T
May 11, 2020 07:39 AM UTC
Hi Vignesh Natarajan,
thanks for your answer.
Query: “I want to know how to use Contain.”
This has been resolved with your help.
Query: “I use "Search" Toolbar.”
I understood that this is a server-side issue.
I would appreciate if you could provide a simple Blazor server-side code that accepts search parameters.
Regards,
Nobuhide
VN
Vignesh Natarajan
Syncfusion Team
May 13, 2020 03:52 AM UTC
Hi Nobuhide,
Thanks for the update.
Query: “I would appreciate if you could provide a simple Blazor server-side code that accepts search parameters.
ODataV4 (.Net Core) does not support Search ($search) by default. Please find the GitHub issues related to it from below
So as a workaround we have manually handled the $search operation in ODataController using ODataQueryOptions and performed the search operation by generating the predicates on our own. Refer the below code example.
|
public PageResult<Book> Get(ODataQueryOptions opts)
{
var results = _db.Books.AsQueryable();
var count = results.Count();
if (opts.OrderBy != null)
results = opts.OrderBy.ApplyTo(results);
if (opts.Filter != null)
{
results = opts.Filter.ApplyTo(results, new ODataQuerySettings()).Cast<Book>();
}
var queryString = opts.Request.Query;
string search = queryString["$search"];
if (search != null)
{
//sarch query is maintained. to oercome that we have used below workaround
string key = search.Split(" OR ")[search.Split(" OR ").Length - 1];
//searched the typed string using where query and retured the results.
results = results.Where(fil => fil.Id.ToString().Contains(key) || fil.Name.Contains(key) || fil.Gender.ToString().Contains(key) || fil.Active.ToString().Contains(key) || fil.CreditLimit.ToString().Contains(key) || fil.RegistrationDate.ToString().Contains(key));
}
if (opts.Skip != null)
results = opts.Skip.ApplyTo(results, new ODataQuerySettings());
if (opts.Top != null)
results = opts.Top.ApplyTo(results, new ODataQuerySettings());
if(search != null)
{
// to remove the QueryValidation for $search as it is not supported by ASP.NEt Core
opts.Request.Query = new QueryCollection();
}
return new PageResult<Book>(results, null, count);
}
|
Similar way you can handle the $search operation in your controller.
For your convenience we have prepared a sample which can be downloaded from below
Note: Above sample, consist of two parts OdataV4Service and BlazorApp1. Kindly run the ODataV4Service first and then run the BlazorApp1.
Please get back to us if you have further queries.
Regards,
Vignesh Natarajan
NT
Nobuhide T
May 14, 2020 01:56 AM UTC
Hi Vignesh Natarajan,
Thank you for your assistance!
I have solved the problem with your help.
Regards,
Nobuhide
VN
Vignesh Natarajan
Syncfusion Team
May 14, 2020 03:54 AM UTC
Hi Nobuhide,
Thanks for the update.
We are glad to hear that you have resolved your query using our solution.
Kindly get back to us if you have further queries.
Regards,
Vignesh Natarajan
NT
Nobuhide T
June 6, 2020 03:13 PM UTC
Hi Vignesh Natarajan,
I have two questions in your sample.
・When I added GridPageSettings,the second page was not be displayed.
・When I search,it doesn't work.
What should I do?
Regards,
Nobuhide
VN
Vignesh Natarajan
Syncfusion Team
June 10, 2020 04:12 AM UTC
Hi Nobuhide,
Query: “When I added GridPageSettings,the second page was not be displayed”
We are able to reproduce the reported issue at our end. Reported issue has occurred since count value is not returned properly from ODataV4 service. Please find the modified code example from below. And also we have simplified the workaround solution provided for search operation.
|
// GET api/values
[HttpGet]
public PageResult<Book> Get(ODataQueryOptions opts)
{
var results = _db.Books.AsQueryable();
var count = results.Count();
if (opts.OrderBy != null)
results = opts.OrderBy.ApplyTo(results);
if (opts.Filter != null)
{
results = opts.Filter.ApplyTo(results, new ODataQuerySettings()).Cast<Book>();
}
var queryString = opts.Request.Query;
string search = queryString["$search"];
if (search != null)
{
//sarch query is maintained. to oercome that we have used below workaround
string key = search.Split(" OR ")[search.Split(" OR ").Length - 1];
//searched the typed string using where query and retured the results.
results = results.Where(fil => fil.Id.ToString().Contains(key) || fil.Name.Contains(key) || fil.Gender.ToString().Contains(key) || fil.Active.ToString().Contains(key) || fil.CreditLimit.ToString().Contains(key) || fil.RegistrationDate.ToString().Contains(key));
}
if(opts.Count != null)
count = results.Count();
if (opts.Skip != null)
results = opts.Skip.ApplyTo(results, new ODataQuerySettings());
if (opts.Top != null)
results = opts.Top.ApplyTo(results, new ODataQuerySettings());
return new PageResult<Book>(results, null, count);
}
|
Please find the modified sample from below
Query2: “When I search,it doesn't work.”
We are not able to reproduce the reported issue at our end while searching a record in Grid. Refer the below screenshot for your reference
|
|
Are you facing the reported issue while typing the value in lower case. If yes, then kindly modify your Where function in BooksController like below
Note: please find the attached sample for query 1.
Kindly get back to us with more details if above solution does not resolve your query.
Regards,
Vignesh Natarajan
SIGN IN To post a reply.
- 7 Replies
- 2 Participants
-
NT Nobuhide T
- May 9, 2020 06:17 AM UTC
- Jun 10, 2020 04:12 AM UTC