PaginatedSearchAndFilter
PaginatedSearchAndFilter copied to clipboard
Generic expando object to handle search from front end MVC view
Hello, this is very nice after playing around I was hoping to get a sample with asp Core View, on how the developers can implement with a generic expando/dynamic object
- [ ] For e.g. if user are searching songs or images or some media, how can we get handle it as a generic request.
- [ ] Also what do we need to configure in the pipeline request handler so it handle it.
For e.g. I am including sample code to get dynamic lists etc. like so, this approach/option would significantly reduce code
private static void PrintSearchedDynamicList(IEnumerable<dynamic> dynamicList)
{
List<string> list = new List<string>();
if (dynamicList.Count() < 1)
{
Console.WriteLine("We couldn't find any matching records.");
}
else
{
foreach (var dynamicObject in dynamicList)
{
foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(dynamicObject))
{
string name = descriptor.Name;
object value = descriptor.GetValue(dynamicObject);
// add some logic to search with this dll, or call the paginatedsearch but how to configure and map
if (list.Contains(name + value) is false)
{
list.Add(name + value);
Console.WriteLine("{0}: {1}", name, value);
}
}
}
}
}
- [ ] For e.g. if user are searching songs or images or some media, how can we get handle it as a generic request.
Unfortunately, I did not get what you mean.
[ ] Also what do we need to configure in the pipeline request handler so it handle it.
Currently we have no plans for pipelines, but I'd love to hear your idea.
Sorry not pipelines, at least based on what i know.
Use case for typical developers: Often we have to create a search and filter page in web aps. It would be sooo helpful, if we could reflect/extract the models attributes and create a search/filter page for the exposed attributes.
We would like to explore/see if there is a json object or C# .net object, that you can expose (which can take any poco model/entity) and spit out the list of search and filter items.
Using that exposed object, we can use that to iterate a list all the search items, and filter items on a page. And we can bind to that.
Check out this page demo.. https://querybuilder.js.org/ where they create the expression for the search, but it would the inverse, where the developer creates the expression and binds it to your search dll.
Do you mean such a thing like that?
public class User
{
public string FirstName { get; set; }
public string LastName { get; set; }
public DateTime DateOfBirth { get; set; }
}
// Generate a list of searchable fields
var searchableFields = SearchableFieldGenerator.Generate<User>();
// searchableFields might contain "FirstName", "LastName", "DateOfBirth"
yes @baranacikgoz it would be even easier if we could annotate the attributes.
hello @baranacikgoz sorry about the confusion, hope you can visualize, I am posting some examples.
Usually theres a poco or viewmodel.. I have to attach search and pagination based on the results on the front end page
Some examples to help visualize,
hello