I've created a custom event document that extends the fields of the normal event document. I've added a field that can keep 0 to many category Ids in a pipe delimited list. Categories are stored in a custom table.

Here is my filter code:

public partial class CMSGlobalFiles_EventCategoryFilter : CMSAbstractDataFilterControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected override void OnInit(EventArgs e)
    {
         SetupControl();

        base.OnInit(e);
    }

    protected override void OnPreRender(EventArgs e)
    {
        if (RequestHelper.IsPostBack())
        {
            setFilter();
         }

        base.OnPreRender(e);
    }

    private void SetupControl()
    {
        if (this.StopProcessing)
        {
            this.Visible = false;
        }

        else if (!RequestHelper.IsPostBack())
        {
            InitializeCategory();
        }

    }

    private void InitializeCategory()
    {
        CustomTableItemProvider customTableProvider = ne CustomTableItemProvider(CMSContext.CurrentUser);

        string where = "";

        string tableName = "customtable.EventCategory";

        DataClassInfo customTable = DataClassInfoProvider.GetDataClass(tableName);

        if (customTable != null)
        {

            DataSet dataSet = customTableProvider.GetItems(tableName, where, null);

            if (!DataHelper.DataSourceIsEmpty(dataSet))
            {
                this.drpCategory.DataSource = dataSet;
                this.drpCategory.DataTextField = "CategoryName";
                this.drpCategory.DataValueField = "ItemGUID";

                this.drpCategory.DataBind();

                this.drpCategory.Items.Insert(0, new ListItem("(all)", "##ALL##"));
            }
        }

    } 

    private void setFilter() 
    {
        string where = null;

        if (this.drpCategory.SelectedValue != null)
        {
            Guid itemGUID = ValidationHelper.GetGuid(this.drpCategory.SelectedValue, Guid.Empty );

            if (itemGUID != Guid.Empty)
            {
                where = "EventCategory LIKE \'%" + itemGUID.ToString() + "%\'";
            }

         }

         if (where != null)
         {
             this.WhereCondition = where;
         }

         this.RaiseOnFilterChanged();
     }

}

This filter works great using a basic repeater and a document data source. When I use the event calendar it does not. I'm using Kentico version 6.0.30

有帮助吗?

解决方案

The problem is in the different lifecycle of the EventCalendar, based on the CMSCalendar control which is based on standard .Net Calendar.

First of all, our developers discovered a way to fix this and allow your scenario to run by default. This fix will be included in the 6.0.33 hotfix (scheduled to go out on Friday 25th). I'm sorry for this inconvenience.

Aside from this upcoming fix, it's also possible to make the EventCalendar to filter its results by modifying (cloning) the web part, integrating the filter controls directly into that web part and set the calendar's Where condition in the OnPreRender before the DataBind as

protected override void OnPreRender(EventArgs e)
{
    calItems.WhereCondition = "some filtering condition";
    ...

If you can hotfix your CMS instance, it would be certainly less effort.

Regards,

Zdenek / Kentico Support

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top