We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

ASP.NET MVC Grid with ITypedList implementation

Hi,

I'm trying to use the essential grid with an ITypedList implementation in order to hide some properties (or show extra calculated properties) from the model class. However, my code does work. Therefore I tried applying my logic to the samples that ship along with the Syncfusion Essential Studio (Enterprise Edition 2013 Volume 2 - Version 11.2.0.25). But that did not work either.

So my question is: What am I doing wrong or did i overlook something ?

The code:
I noticed the code in the file: Controllers\DataBinding\ITypedListDataModelController.cs
was not set up to use the ITypedList so i changed that to:

public partial class DataBindingController : ApplicationController
    {
        /// <summary>
        /// Used for rendering the grid initially.
        /// </summary>
        /// <returns>Veiw page, it displays the Grid</returns>

        public ActionResult ITypedListDataModel(string datatype)
        {
            ViewData["data"] = new StudentDetailsDataContext().GetStudent;
            return View();
        }
       
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult ITypedListDataModel(PagingParams args, GridColumn<ITyped.Models.Student> column)
        {
            var data = new StudentDetailsDataContext().GetStudent;
            return data.GridJSONActions<object>();
        }
    }

file: Models\IListTyed.cs
namespace ITyped.Models
{
    [Serializable()]
    public class SortableBindingList<T> : BindingList<T>, ITypedList
    {
        [NonSerialized()]
        private PropertyDescriptorCollection properties;

        public SortableBindingList()
            : base()
        {
            // Get the 'shape' of the list. 
            // Only get the public properties marked with Browsable = true.
            PropertyDescriptorCollection pdc = TypeDescriptor.GetProperties(
                typeof(T),
                new Attribute[] { new BrowsableAttribute(true) });

            // Sort the properties.
            properties = pdc.Sort();
        }

        #region ITypedList Implementation

        public PropertyDescriptorCollection GetItemProperties(PropertyDescriptor[] listAccessors)
        {
            var propList = new List<PropertyDescriptor>
                {
                    new MyPropDesc("My prop !", null)
                };
            return new PropertyDescriptorCollection(propList.ToArray());
        }

        // This method is only used in the design-time framework 
        // and by the obsolete DataGrid control.
        public string GetListName(PropertyDescriptor[] listAccessors)
        {
            return typeof(T).Name;
        }

        private class MyPropDesc : PropertyDescriptor
        {
            public MyPropDesc(string name, Attribute[] attrs) : base(name, attrs)
            {
            }

            public MyPropDesc(MemberDescriptor descr) : base(descr)
            {
            }

            public MyPropDesc(MemberDescriptor descr, Attribute[] attrs) : base(descr, attrs)
            {
            }

            public override bool CanResetValue(object component)
            {
                return false;
            }

            public override object GetValue(object component)
            {
                var s = (Student) component;
                return s.Title + " uc: " + s.UniversityCode;
            }

            public override void ResetValue(object component)
            {
            }

            public override void SetValue(object component, object value)
            {
            }

            public override bool ShouldSerializeValue(object component)
            {
                return false;
            }

            public override Type ComponentType
            {
                get { return typeof(Student); }
            }

            public override bool IsReadOnly
            {
                get { return true; }
            }

            public override Type PropertyType
            {
                get { return typeof(string); }
            }
        }

        #endregion
    }

    public class Student
    {

        public Nullable<Int32> UniversityCode { get; set; }

        public string Title { get; set; }


        public Nullable<Int32> Duration { get; set; }


        public double CourseFees { get; set; }


        public double CGPA { get; set; }

    }
    public class StudentDetailsDataContext
    {
        public SortableBindingList<Student> GetStudent
        {
            get
            {

                int code = 10000;
                var data = new SortableBindingList<Student> { };
                for (long i = 0; i < 1000; i++)
                {
                    Student[] s = new Student[10];
                    s[0] = new Student() { UniversityCode = code + 1, CourseFees = 2000.00, CGPA = 7.52, Duration = 90, Title = "Distributed Component Architecture" };
                    s[1] = new Student() { UniversityCode = code + 2, CourseFees = 1000.00, CGPA = 9.55, Duration = 60, Title = "Data Structures" };
                    s[2] = new Student() { UniversityCode = code + 3, CourseFees = 1750.00, CGPA = 9.03, Duration = 75, Title = "Neural Networks" };
                    s[3] = new Student() { UniversityCode = code + 4, CourseFees = 2000.00, CGPA = 8.91, Duration = 90, Title = "Genetic Algorithms" };
                    s[4] = new Student() { UniversityCode = code + 5, CourseFees = 1000.00, CGPA = 9.55, Duration = 30, Title = "Grid Computing" };
                    s[5] = new Student() { UniversityCode = code + 6, CourseFees = 2500.00, CGPA = 9.87, Duration = 60, Title = "Cloud Computing" };
                    s[6] = new Student() { UniversityCode = code + 7, CourseFees = 1500.00, CGPA = 9.75, Duration = 90, Title = "Enterprise Computing" };
                    s[7] = new Student() { UniversityCode = code + 8, CourseFees = 1250.00, CGPA = 9.66, Duration = 45, Title = "Mobile Computing" };
                    s[8] = new Student() { UniversityCode = code + 9, CourseFees = 1000.00, CGPA = 8.33, Duration = 60, Title = "WAP and XML" };
                    s[9] = new Student() { UniversityCode = code + 10, CourseFees = 1500.00, CGPA = 8.66, Duration = 75, Title = "Design Patterns" };
                    foreach (Student studnt in s)
                    {
                        data.Add(studnt);
                    }

                    code += 10;
                }
                return data;
            }
        }
    }
}

I Highlighted my code in bold.

I left the rest of the sample code unchanged.

Thanks in advance.

Kind regards,
Yanik Ceulemans

3 Replies

BM Bala Murugan A.S Syncfusion Team July 25, 2013 11:42 AM UTC

Hi Yanik Ceulemans,

 

Thanks for using Syncfusion Products.

 

We have tried by creating the sample with ITypedList binding along with your code and its working fine in our end. The sample can be downloaded from the below link.

 

Sample: ITypedList_SyncfusionGrid.zip

 

Please try the above sample and if any issues, could you please replicate you issue in the above sample and send back to us with more information so that we could able to analyze and provide you a better solutions quickly. The information provided would be a great help for us to resolve your issue.

 

Please let us know if you have any concerns.

 

Regards,

Bala Murugan A.S



YC Yanik Ceulemans July 26, 2013 01:15 PM UTC

Hi Bala Murugan,

I fired up the example project attached in your reply to test whether it had my desired functionality. But it does not. The grid shows all of the properties from the student model, even though the code in the "GetItemProperties" method only defines 1 property called "My prop !". The desired functionality would be that the grid only shows that 1 property.

See attached screenshot for more information.

Kind Regards,
Yanik Ceulemans


syncfusiongrid_cf0bd598.zip


AM Abdul Matin M Syncfusion Team July 31, 2013 01:10 PM UTC

Hi Yanik Ceulemans,

 

Thanks for using Syncfusion products.

 

We regret to let you know that we can provide solution for this only through Direct-Trac incident, so could you please create the incident in your direct trac account.

You can login to your Direct-Trac account using the credentials and password that are provided by our sales team to create incident. I would request you to use the following link to login to your DT account.

 

http://www.syncfusion.com/account/Logon

 

Please let us know if you need further assistance. We would be happy to assist you.

 

Regards,

Abdul Matin M


Loader.
Live Chat Icon For mobile
Up arrow icon