Custom Task Field with value Undefined

2 posts, 1 answers
  1. Sebastian
    Sebastian avatar
    4 posts
    Member since:
    Jun 2017

    Posted 14 Jul Link to this post

    Hello,

    I trying to create a custom task field "Description" like in the documentation DOC, but  binding RadGantt's Datasource  simply in Page_Load event.

     

    My Code:

    public class CustomGanttTaskFactory : ITaskFactory
    {
        Task ITaskFactory.CreateTask()
        {
            return new CustomTask();
        }
    }
     
    public class CustomTask : Task
    {
        public CustomTask()
            : base()
        {
        }
     
        public string Description
        {
            get { return (string)(ViewState["Description"] ?? ""); }
            set { ViewState["Description"] = value; }
        }
     
        protected override IDictionary<string, object> GetSerializationData()
        {
            var dict = base.GetSerializationData();
            dict["Description"] = Description;
            return dict;
        }
     
        public override void LoadFromDictionary(System.Collections.IDictionary values)
        {
            base.LoadFromDictionary(values);
     
            Description = (string)values["Description"];
        }
    }

     

    Page_Load

    List<ITask> newFinalTask = new List<ITask>();
            newFinalTask.Add(new CustomTask { ID = 1, Description = "TEST1", OrderID = 1, ParentID = null, Title = "TITLE A", Start = new DateTime(2017, 01, 10, 0, 0, 0), End = new DateTime(2017, 01, 19, 23, 59, 59), PercentComplete = 0.20M, Expanded = false, Summary = true });
            newFinalTask.Add(new CustomTask { ID = 2, Description = "TEST2", OrderID = 2, ParentID = 1, Title = "SUB A1", Start = new DateTime(2017, 01, 10, 0, 0, 0), End = new DateTime(2017, 01, 15, 23, 59, 59), PercentComplete = 0.20M, Expanded = false });
            newFinalTask.Add(new CustomTask { ID = 3, Description = "AAAA", OrderID = 3, ParentID = 1, Title = "SUB A2", Start = new DateTime(2017, 01, 16, 0, 0, 0), End = new DateTime(2017, 01, 19, 23, 59, 59), PercentComplete = 0.20M, Expanded = false });
            newFinalTask.Add(new CustomTask { ID = 4, Description = "BB", OrderID = 4, ParentID = null, Title = "TITLE B", Start = new DateTime(2017, 01, 20, 0, 0, 0), End = new DateTime(2017, 01, 31, 23, 59, 59), PercentComplete = 0.20M, Expanded = false, Summary = true });
            newFinalTask.Add(new CustomTask { ID = 5, Description = "CCCC", OrderID = 5, ParentID = 4, Title = "SUB B1", Start = new DateTime(2017, 01, 20, 0, 0, 0), End = new DateTime(2017, 01, 31, 23, 59, 59), PercentComplete = 0.20M, Expanded = false });
     
    RadGantt1.DataSource = newFinalTask;

     

    Desing

    <telerik:RadGantt runat="server" ID="RadGantt1"
        Enabled="true"
        ReadOnly="True"
        AllowSorting="False"
        AutoGenerateColumns="false">
        <DataBindings>
            <TasksDataBindings
                IdField="ID"
                TitleField="Title"
                StartField="Start"
                EndField="End"
                PercentCompleteField="PercentComplete"
                OrderIdField="OrderID"
                SummaryField="Summary"
                ParentIdField="ParentID"  />
        </DataBindings>
        <CustomTaskFields>
            <telerik:GanttCustomField PropertyName="Description" ClientPropertyName="description" Type="String"/>
        </CustomTaskFields>
        <Columns>
            <telerik:GanttBoundColumn DataField="ID" HeaderText="ID" AllowEdit="false" AllowSorting="false"></telerik:GanttBoundColumn>
            <telerik:GanttBoundColumn DataField="Description" HeaderText="Desc." DataType="String" UniqueName="Description"></telerik:GanttBoundColumn>
            <telerik:GanttBoundColumn DataField="Title" HeaderText="ACTIVITY" AllowEdit="false" AllowSorting="false"></telerik:GanttBoundColumn>
            <telerik:GanttBoundColumn DataField="Start" HeaderText="START" DataFormatString="dd/MM/yyyy" AllowEdit="false" AllowSorting="false"></telerik:GanttBoundColumn>
            <telerik:GanttBoundColumn DataField="End" HeaderText="END" DataFormatString="dd/MM/yyyy" AllowEdit="false" AllowSorting="false"></telerik:GanttBoundColumn>
            <telerik:GanttBoundColumn DataField="PercentComplete" HeaderText="% COMPLETED" AllowEdit="false" AllowSorting="false"></telerik:GanttBoundColumn>
        </Columns>
    </telerik:RadGantt>

     

    But displaying "undefined" in column "Description (Desc.)"

    Someone help me with this please?

     

    Thanks

     

     

  2. Answer
    Peter
    Peter avatar
    2 posts
    Member since:
    May 2016

    Posted 28 Jul Link to this post

    Hi Sebastian, 

    In order to use a custom Task class, you have to create a custom Provider as described in the documentation you have provided a link for: Custom Tasks Field.

Back to Top