custom filter with a drop down list from the databse

hassan kalach asked on September 13, 2017 15:44

okay the thing is i have a custom filter where it should display all the category of a certain field as a drop down list , and i do not wont to add them in a static way i want to get them directly from the database so any suggestion ? and please any one who would like to answer try to give details as much as you can since i am still new in this

Correct Answer

Trevor Fayas answered on September 15, 2017 15:40

Inside of Kentico each Class has an Info and InfoProvider class (some also have Helper classes).

The "____Info" (ex CategoryInfo) represents the actual item, and has all of it's properties (ex

CategoryInfo MyCategory;
MyCategory.CategoryName;
MyCategory.CategoryDisplayName;

The "____InfoProvider" (ex CategoryInfoProvider) has methods that allow you to retrieve your Info objects, as well as other related functions. Most all Providers have a Get_____Info() (ex CategoryInfoProvider.GetCategoryInfo("TheCodeName")) that allows you to get the Info object by ID, CodeName, or GUID. They also have a Get_____s() (ex CategoryInfoProvider.GetCategories()) which is a Queriable object.

So in your case, you want to do something along the lines of:

var MyCategories = CategoryInfoProvider.GetCategories().Where("Some Where Condition").OrderBy("CategoryDisplayName");

You can also create your own Classes using modules, and generate the Info and InfoProvider classes for those, but that is probably not needed here. Hope that helps educate you!

0 votesVote for this answer Unmark Correct answer

Recent Answers


Trevor Fayas answered on September 13, 2017 16:56

When creating a custom filter, you need to create your control and then have it render the WHERE condition that will be passed to the thing you're filtering.

You can have an ASP Drop down control on your custom filter and populate it dynamically, such as using Kentico's API to execute a query (QueryInfoProvider), or use the CategoryInfoProvider or related calls to get the Categories you want the drop down to contain, and loop through the CategoryInfo objects and add new ListItem to the drop down.

The Documentations "InitializeDepartments()" function shows how it got a dataset from the API and assigned the drop down to it.

https://docs.kentico.com/k10/custom-development/developing-web-parts/advanced-web-part-development-scenarios/developing-custom-filters

Additionaly if you really want to go a simple route and you have Kentico 10, i have finished (but not yet ported and published to the marketplace) a Universal Page Filter and Universal Query Filter web part that you can pass it a SQL select statement to build a drop down or radio list, and then define how that selected value renders into a WHERE condition without needing to touch code. I can get it to you if you wish.

0 votesVote for this answer Mark as a Correct answer

hassan kalach answered on September 15, 2017 15:04

@trevor fayas i have seen the provided answer and i am well aware of it , the only problem is in the following code // Gets all product departments from the system's database var departments = DepartmentInfoProvider.GetDepartments(); if theres an example on how to creat DepartmentInfoProvider class and the GetDepartments() function;

thank you for your help

0 votesVote for this answer Mark as a Correct answer

hassan kalach answered on September 15, 2017 16:17

thank you for your answer i will try to apply what you suggested and i will get back to you with result :D . either way thank you very much

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.