Still can't get things to work ...
I've simplified my code to some samples, perhaps you can tell me where I'm f-ing things up ....
Sample 5 is what I actually need, but the troubles start whenever I'm combining or use a date ... and I need to do both ...
SAMPLE 1: Filter on just checkbox list values with an OR, THIS WORKS
@inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.ParagraphViewModel>
@{
var selectedCategoryId = Model.Item.GetInt32("CategoryId");
var listTake = Model.Item.GetInt32("AmountShown") + 1;
var listFilter = "";
var listOrderBy = "Id";
var listOrderByDirection = "Descending";
// Filter by categoryId
if (selectedCategoryId > 0) {
listFilter += string.Format("({1} contains '{0}' or {2} contains '{0}' or {3} contains '{0}' or {4} contains '{0}')",
selectedCategoryId,
"Field1", // checkbox list value, can contain 1 or 1,2,3
"Field2", // checkbox list value, can contain 1 or 1,2,3
"Field3", // checkbox list value, can contain 1 or 1,2,3
"Field4"); // checkbox list value, can contain 1 or 1,2,3
}
var myList = RenderItemList(new
{
ItemType = "MyItem",
ListTemplate = "../ItemPublisher/List/List.cshtml",
ListSourceType = "Area",
ListSourceArea = areaId,
ItemFieldsList = "*",
ListPageSize = listTake,
ListViewMode = "Partial",
ListShowFrom = 1,
ListShowTo = listTake,
IncludeParagraphItems = true,
ListOrderBy = listOrderBy,
ListOrderByDirection = listOrderByDirection,
Filter = listFilter
});
@myList
}
SAMPLE 2: Filter on a text value, THIS WORKS
@inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.ParagraphViewModel>
@{
var titleFilterTex = Model.Item.GetString("Title");
var listTake = Model.Item.GetInt32("AmountShown") + 1;
var listFilter = "";
var listOrderBy = "Id";
var listOrderByDirection = "Descending";
// Filter by categoryId
if (!string.IsNullOrWhiteSpace(titleFilterTex)) {
listFilter += string.Format("Title contains '{0}'", titleFilterTex);
}
var myList = RenderItemList(new
{
ItemType = "MyItem",
ListTemplate = "../ItemPublisher/List/List.cshtml",
ListSourceType = "Area",
ListSourceArea = areaId,
ItemFieldsList = "*",
ListPageSize = listTake,
ListViewMode = "Partial",
ListShowFrom = 1,
ListShowTo = listTake,
IncludeParagraphItems = true,
ListOrderBy = listOrderBy,
ListOrderByDirection = listOrderByDirection,
Filter = listFilter
});
@myList
}
SAMPLE 3: COMBINING the above together, THIS DOES NOT WORK
@inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.ParagraphViewModel>
@{
var titleFilterTex = Model.Item.GetString("Title");
var selectedCategoryId = Model.Item.GetInt32("CategoryId");
var listTake = Model.Item.GetInt32("AmountShown") + 1;
var listFilter = "";
var listOrderBy = "Id";
var listOrderByDirection = "Descending";
// Filter by categoryId
if (selectedCategoryId > 0) {
listFilter += string.Format("({1} contains '{0}' or {2} contains '{0}' or {3} contains '{0}' or {4} contains '{0}')",
selectedCategoryId,
"Field1", // checkbox list value, can contain 1 or 1,2,3
"Field2", // checkbox list value, can contain 1 or 1,2,3
"Field3", // checkbox list value, can contain 1 or 1,2,3
"Field4"); // checkbox list value, can contain 1 or 1,2,3
}
// Filter by categoryId
if (!string.IsNullOrWhiteSpace(titleFilterTex)) {
if (!string.IsNullOrWhiteSpace(listFilter)) {
listFilter += " and ";
}
listFilter += string.Format("Title contains '{0}'", titleFilterTex);
}
var myList = RenderItemList(new
{
ItemType = "MyItem",
ListTemplate = "../ItemPublisher/List/List.cshtml",
ListSourceType = "Area",
ListSourceArea = areaId,
ItemFieldsList = "*",
ListPageSize = listTake,
ListViewMode = "Partial",
ListShowFrom = 1,
ListShowTo = listTake,
IncludeParagraphItems = true,
ListOrderBy = listOrderBy,
ListOrderByDirection = listOrderByDirection,
Filter = listFilter
});
@myList
}
What am I doing wrong here?
SAMPLE 4: FILTERING ON ONE DATE, THIS DOES NOT WORK
@inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.ParagraphViewModel>
@{
var titleFilterTex = Model.Item.GetString("Title");
var listTake = Model.Item.GetInt32("AmountShown") + 1;
var listFilter = "";
var listOrderBy = "Id";
var listOrderByDirection = "Descending";
// Filter by start date (start date is in the future)
listFilter += "StartDateTime > \"" + DateTime.Today.ToString("yyyy/MM/dd") + "\""; // how does this differ from: listFilter += string.Format("StartDateTime > {0}", DateTime.Today.ToString("yyyy/MM/dd"))
var myList = RenderItemList(new
{
ItemType = "MyItem",
ListTemplate = "../ItemPublisher/List/List.cshtml",
ListSourceType = "Area",
ListSourceArea = areaId,
ItemFieldsList = "*",
ListPageSize = listTake,
ListViewMode = "Partial",
ListShowFrom = 1,
ListShowTo = listTake,
IncludeParagraphItems = true,
ListOrderBy = listOrderBy,
ListOrderByDirection = listOrderByDirection,
Filter = listFilter
});
@myList
}
SAMPLE 5: WHAT I ACTUALLY NEED !
@inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.ParagraphViewModel>
@{
var selectedCategoryId = Model.Item.GetInt32("CategoryId");
var listTake = Model.Item.GetInt32("AmountShown") + 1;
var listFilter = "";
var listOrderBy = "Id";
var listOrderByDirection = "Descending";
// Filter by categoryId
if (selectedCategoryId > 0)
{
listFilter += string.Format("({1} contains '{0}' or {2} contains '{0}' or {3} contains '{0}' or {4} contains '{0}')",
selectedCategoryId,
"Field1", // checkbox list value, can contain 1 or 1,2,3
"Field2", // checkbox list value, can contain 1 or 1,2,3
"Field3", // checkbox list value, can contain 1 or 1,2,3
"Field4"); // checkbox list value, can contain 1 or 1,2,3
}
// Filter by dates (start date is in the future or end date is not null and in the future
if (!string.IsNullOrWhiteSpace(listFilter))
{
listFilter += " and ";
}
listFilter += "(StartDateTime > \"" + DateTime.Today.ToString("yyyy/MM/dd") + "\" or (EndDateTime != \"" + null + "\" and EndDateTime > \"" + DateTime.Today.ToString("yyyy/MM/dd") + "\" ))";
var myList = RenderItemList(new
{
ItemType = "MyItem",
ListTemplate = "../ItemPublisher/List/List.cshtml",
ListSourceType = "Area",
ListSourceArea = areaId,
ItemFieldsList = "*",
ListPageSize = listTake,
ListViewMode = "Partial",
ListShowFrom = 1,
ListShowTo = listTake,
IncludeParagraphItems = true,
ListOrderBy = listOrderBy,
ListOrderByDirection = listOrderByDirection,
Filter = listFilter
});
@myList
}