The EntitySpaces Community

Share and learn about the EntitySpaces Architecture.
Welcome to The EntitySpaces Community Sign in | Join | Help
in
Home Forums Photos

Sorting a custom column

Last post 04-15-2008, 11:49 AM by Mike.Griffin. 3 replies.
Sort Posts: Previous Next
  •  04-15-2008, 9:58 AM 8865

    Sorting a custom column

    I've searched the forums but have not found the answer.

    I have created a custom column (extended column) on my entity.  I have a collection of these entities bound to a grid.  I can sort (by clicking the DGV header) the basic columns, but when I click the header on my extended column nothing happens.  No error, nothing.

    I'm wondering if there is something I need to do to support sorting for extended columns?

    Here is the code where I'm creating the extended columns (properties)

     

    Code:
    1    protected override List GetLocalBindingProperties()
    2    {
    3            List props = new List();
    4            props.Add(new esPropertyDescriptor(this, "StatusTitle", typeof(string)));
    5            props.Add(new esPropertyDescriptor(this, "DocumentTypeTitle", typeof(string)));
    6    
    7            return props;
    8    }
    
     
  •  04-15-2008, 10:47 AM 8867 in reply to 8865

    Re: Sorting a custom column

    Currently the answer is "no". We use the DataTable to sort (DataView really) and unless you have a grid like Telerik and DevX which sort externally from the collections (I think both of those do) it wont work. You would have to have your extended columns live in the DataTable for it to work.

    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  04-15-2008, 11:08 AM 8868 in reply to 8867

    Re: Sorting a custom column

    Are you still on vacation?

    My extended columns are "Formatted" version of columns in my Datatable. For example:

    DocTypeId - DataTable column

    DocTypeTitle - extended property that returns a formatted string based on the value of DocTypeId

    Maybe a good workaround would be to handle the column click event, assess the column clicked and sort the collection on the underlying DataTable column.  So if a user clicked the DocTypeTitle column I would sort the DocTypeId column.

    Does that make sense?  Seem like a reasonable solution? 

  •  04-15-2008, 11:49 AM 8870 in reply to 8868

    Re: Sorting a custom column

    Here's one possible solution.

     

    Code:
    namespace BusinessObjects
    {
    public partial class EmployeesCollection : esEmployeesCollection
    {
    public bool CustomLoad()
    {
    // Query not really shown here ....
    if (this.query.Load())
    {
    // We add a column called "FullName" which uses the DataColumn.Expression and derives
    // it's value from other columns

    DataColumn col = new DataColumn("FullName", Type.GetType("System.String"));
    col.Expression = EmployeesMetadata.ColumnNames.LastName +
    "+ ', ' + " + EmployeesMetadata.ColumnNames.FirstName;

    this.Table.Columns.Add(col);
    }
    }
    }
    }
     

    Then you just have your "FullName" extended property work like this:

     

    Code:
    public string FullName
    {
    get { return (string)this.GetColumn("FullName"); }
    set { this.SetColumn("FullName", value); }
    }

     

    It should then sort okay .... 


    EntitySpaces | Twitter | BLOG | Please honor our Software License
View as RSS news feed in XML