locked
Dynamic filter order by RRS feed

  • Question

  • User-847866960 posted

    I've customized one of my pages not to use the templates.  I've removed the FilterRepeater and just have one Dynamic Filter on the page.  My question is, is there a way to order the contents of the drop down list that the Dynamic Filter creates?  Do I need to create a partial class for that table and do something on the OnLoaded event?  Thanks in advance. 

    Wednesday, December 19, 2007 12:19 PM

Answers

  • User-797310475 posted

    Thanks for the input everyone,

    We already have plans to add extra metadata attributes to let you provide friendlier names for columns and filters, as well as better customization for sorting. They will come in particularily handy if you have an externally created data model that you can't edit yourself.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 20, 2007 3:16 PM
  • User-797310475 posted

     Hi Case,

    first of all because you are referring to DynamicGridView it's probably the case that you are using the December '07 CTP. That version is quite outdated at this point and I would invite you to download either the .NET Framework 3.5 SP1 or the cutting edge version of Dynamic Data on Code Gallery.

    Once you have the recent bits, you can use DisplayColumnAttribute.SortColumn to provide sorting information.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, May 23, 2008 11:27 AM
  • User-330204900 posted

    Have a look at this I think it may be what you need:

    [MetadataType(typeof(EmployeeMD))]
    [DisplayColumn("LastName","LastName",false)]
    public partial class Employee
    {
        public class EmployeeMD
        {
            public object EmployeeID { get; set; }
            [UIHint("MultilineText")]
            public object LastName { get; set; }
            public object Title { get; set; }
            public object TitleOfCourtesy { get; set; }
    //... more fields here } }

    the DisplayColumn takes 3 parameters

    1. Is the column to display
    2. Is the column to sort on
    3. Is set to true for dort descending

    This affects the Filters and the ForeignKey_Edit filedTemplates.

    Hope this helps [:D]

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, November 26, 2008 8:56 AM
  • User-330204900 posted

    You create a partial class file (in the App_Code folder in a file based website) along with the Linq to SQL files. You create a class with the partial class that represent the entity in the Linq to SQL classes (Look in the <ModelName>.designer.cs file for the class names etc) and then add the metadata, also see these videos here: http://www.asp.net/learn/3.5-SP1/ in the ASP.NET Dynamic Data section.

    Hope this helps [:D]

     

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, November 26, 2008 9:20 AM

All replies

  • User-1798442633 posted

     That's a great question.  I was just about to post that one myself . . .

    Wednesday, December 19, 2007 2:43 PM
  • User-797310475 posted

    There currently is no way to customize this. For future releases, we are thinking of having an extra metadata attribute that would let you declare the column to sort on (plus asc/desc). Is there any extra functionality you would like to see in this area?

    Thanks

    Wednesday, December 19, 2007 9:05 PM
  • User-847866960 posted

    Well, I started customizing the dynamic filter because I needed a human readable label next to the drop down list, not just the table name.  It would be nice to have an attribute for every column and table name so that you could provide your own custom string that would be displayed in the grid column headers and the filter labels etc.

    Thursday, December 20, 2007 9:55 AM
  • User-598858272 posted

    Although it may not be practical for your solution, one workaround would be to rename the tables in the LinqToSql class.  You can click do it directly in the designer.

    Thursday, December 20, 2007 10:03 AM
  • User-847866960 posted
    Strange, I swear I tried that before and it didn't work, but now it is.  Thanks.
    Thursday, December 20, 2007 10:13 AM
  • User-849584445 posted

    For some reason, after you rename the tables in your LINQ to SQL diagram, you have to close the diagram and reload it in order for the new names to take effect.  The names change in the diagram in real time, however they are not seen programmatically untill you reload the diagram.  The same thing happened to me.  I'm afraid it may be similar to the cashing issue in another topic on this forum which we are currently waiting on a work around for.

    Thursday, December 20, 2007 10:24 AM
  • User-797310475 posted

    Thanks for the input everyone,

    We already have plans to add extra metadata attributes to let you provide friendlier names for columns and filters, as well as better customization for sorting. They will come in particularily handy if you have an externally created data model that you can't edit yourself.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 20, 2007 3:16 PM
  • User271120571 posted

    So I was wondering if this issue has been resolved yet.

    I am trying to sort a automatically generated dropdown in an DynamicGridView, and would love to know if there is a metadata attribute I can use to do that.

    Right now it is sorting by the column's ID field rather than its Name field. 

    thanks,

    case
     

    Friday, May 23, 2008 10:54 AM
  • User-330204900 posted

    Marcin in the third post in this thread just said there is no way to do this currently (and I suspect in the verion that will RTM) to do the sort. However Marcing is also doing some samples see here one sample is Extending the FilterRepeater which may give us insite as to how we could do it our selves.

    Friday, May 23, 2008 11:05 AM
  • User-797310475 posted

     Hi Case,

    first of all because you are referring to DynamicGridView it's probably the case that you are using the December '07 CTP. That version is quite outdated at this point and I would invite you to download either the .NET Framework 3.5 SP1 or the cutting edge version of Dynamic Data on Code Gallery.

    Once you have the recent bits, you can use DisplayColumnAttribute.SortColumn to provide sorting information.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, May 23, 2008 11:27 AM
  • User-1878671908 posted

    I know that this is an older posting.  Has this been added yet?  I really desparately need this functionality.

    I have seen posts about work arounds, but am too much of a noobie to have a clue what they are talking about.  I am just now learning VB, so people throwing code at me and saying "add it" doesn't help me much.  I really need to know more specifics, like WHERE to add it.

    If anyone has any suggestions or help they can provide, I sure would appreciate it.

     I have tried this "DisplayColumnAttribute.SortColumn" and the link doesn't work...so tried searching for it, but doesn't seem to be for the Filters...at least not from what I am understanding.

     Thanks, Ann

    Wednesday, November 26, 2008 8:15 AM
  • User-330204900 posted

    Have a look at this I think it may be what you need:

    [MetadataType(typeof(EmployeeMD))]
    [DisplayColumn("LastName","LastName",false)]
    public partial class Employee
    {
        public class EmployeeMD
        {
            public object EmployeeID { get; set; }
            [UIHint("MultilineText")]
            public object LastName { get; set; }
            public object Title { get; set; }
            public object TitleOfCourtesy { get; set; }
    //... more fields here } }

    the DisplayColumn takes 3 parameters

    1. Is the column to display
    2. Is the column to sort on
    3. Is set to true for dort descending

    This affects the Filters and the ForeignKey_Edit filedTemplates.

    Hope this helps [:D]

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, November 26, 2008 8:56 AM
  • User-1878671908 posted

    Again...WHERE does it go?  I have no idea which file this would need to go in.  I already have this information, but have tried to figure out where to put it and cannot determine it.

    Do you put it into the ForeignKey_Edit Template?  Do you put it in the Custom Template for the Table you want to use it on?  Do you put it in the Default page?  What about the pages that handle ALL of the Tables...does it go in that file?

    Also, is 'EmployeeMD' the table name or is 'Employee' the table name?  Whichever is not the table name...what is it?  A column in the table?  Or a new name?

    I kind of get the feeling that the 'EmployeeMD' is the table and that the 'public objects' are the columns...  Is that right?

      Thanks, Ann

    Wednesday, November 26, 2008 9:10 AM
  • User-330204900 posted

    You create a partial class file (in the App_Code folder in a file based website) along with the Linq to SQL files. You create a class with the partial class that represent the entity in the Linq to SQL classes (Look in the <ModelName>.designer.cs file for the class names etc) and then add the metadata, also see these videos here: http://www.asp.net/learn/3.5-SP1/ in the ASP.NET Dynamic Data section.

    Hope this helps [:D]

     

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, November 26, 2008 9:20 AM
  • User-1878671908 posted

    Okay, I have done what I think you said to do, but am getting errors.

    I created a new class file in the App_Code folder called "Series_Master_Best_Cost", which is the name of my table, and it is how the class is declared in the 'designer.vb' file in the App_Code folder.

    I changed the parameters in 'DisplayColumn' to "User_Master", which is the column name for the Filter that I need sorted in alphabetical order.

    It is complaining about 'DisplayColumn', saying "Declaration Expected".  I made a declaration, but still didn't seem to like it.

    I had to comment out 'Option Strict On' because it kept complaining about the parameters for 'DisplayColumn', but that still did not fix things.

    Here is the error information I am getting:

    Input string was not in a correct format.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.FormatException: Input string was not in a correct format.

    Source Error:

    Line 6:  <MetadataType(GetType(Series_Master_Best_Cost))> _
    Line 7: Partial Public Class [Series_Master_Best_Cost]
    Line 8: Dim DisplayColumn("USER_MASTER", "USER_MASTER", False)
    Line 9: Public Class [Series_Master_Best_Cost]
    Line 10:

    Source File: D:\Intranet\BestCost\App_Code\Series_Master_Best_Cost.vb    Line:

    Wednesday, November 26, 2008 10:05 AM
  • User-1878671908 posted

    Got the error to go away.  Found some information on http://msdn.microsoft.com/en-us/library/cc679189.aspx that showed a little different information, but still is not sorting my column.  I am guessing it is now a matter of me not having the right information in each of the parameters, classes, or types.

    This is my partial class file:

    Imports Microsoft.VisualBasic
    Imports System.Web.DynamicData
    Imports System.ComponentModel
    Imports System.ComponentModel.DataAnnotations


    <MetadataType(GetType(Series_Master_Best_Cost))> _
    Partial Public Class Series_Master_Best_Cost

        <DisplayColumn("USER_MASTER", "USER_MASTER", False)> _
        Public Class Series_Master_Best_Cost

        End Class
    End Class

    Is there something else that I am missing?

    I also tried 'Series_Master_Best_CostMD'  in the MetadataType and Public Class (not Partial), which seemed to follow what others had done, but then it said that the type was not defined.

    What is the difference between DisplayColumnAttribute and DisplayColumn...they seem to both be used in that page referenced above.

    Anything else you can tell me?

    Thanks, Ann

    Wednesday, November 26, 2008 10:31 AM
  • User-330204900 posted

    Imports Microsoft.VisualBasic
    Imports System.Web.DynamicData
    Imports System.ComponentModel
    Imports System.ComponentModel.DataAnnotations


    <MetadataType(GetType(Series_Master_Best_Cost))> _
    <DisplayColumn("USER_MASTER", "USER_MASTER", False)> _
    Partial Public Class Series_Master_Best_Cost

        Public Class Series_Master_Best_Cost

        End Class
    I think it should be more like this the table level attributes on the partial class.

    Wednesday, November 26, 2008 1:27 PM
  • User-1878671908 posted

     Has anyone else been able to get this to work?  I have changed it as suggested (and closed the second class too), and it still does not sort the filtered list...or anything else for that matter...

    There must be something other than this that I am not getting done.

    While I am a novice, it seems to me that this is trying to sort the COLUMN "user_master", not the filtered dropdown list, but that isn't sorted either...

     This wouldn't be such a big issue, but we have thousands of employees in our company and trying to find one of them in an unsorted list is not possible!

     Any help would be great!

    HAPPY THANKSGIVING TO ALL!!!

    Thanks, Ann

     

    Wednesday, November 26, 2008 2:14 PM
  • User-797310475 posted

    Maybe an example will help; let's assume that your model generates the folowing classes (sorry for using C# syntax):

    public partial class Product {
      public Category MyCategory;
    }
    
    public partial class Category {
      public string Name;
      public int Code;
    }

    Now say you are displaying your Products list. Since Product has a foreign key reference to Category, a filter in the form of a drop-down will be generated for the MyCategory column. I am assuming now that you want to customize the order in which the items appear in this dropdown. If you are trying to do something different, please clarify.

    So to customize this ordering, you would decorate the Category class (since this is the type of the MyCategory property on Product) with DisplayColumnAttribute, initialized as follows:

    [DisplayColumnAttribute("Name", "Code", true)]
    public partial class Category {
    }

    This will cause Dynamic Data to display the values in the dropdown using the value of the Name property, but they will be ordered in descending order based on the Code property.

    As was noted earlier, you would add it in code to your App_Code folder (if in a WebSite project) or just as a class anywhere inside of a Web Application project. Since this is a class-level attribute, you don't need to use MetadataTypeAttribute.

    You asked about the difference between [DisplayColumnAttribute] and [DisplayColumn]. There is none. The compiler automatically infers that if you have [DisplayColumn] you actually mean [DisplayColumnAttribute]. Note that this behavior only applies to attributes when they are used to decorate code (and not ones instantiated in code).

    Wednesday, November 26, 2008 3:59 PM
  • User-330204900 posted

    Hi Tigra68 nI've just tried it and all seems to be working fine in c# and VB

    here's the VB to show:

     

    <MetadataType(GetType(Employee.EmployeeMD))> _
    <DisplayColumn("LastName", "LastName", True)> _
    Partial Public Class [Employee]
        Public Class [EmployeeMD]
            Public EmployeeID As Object
            Public LastName As Object
            Public FirstName As Object
            Public Title As Object
            Public TitleOfCourtesy As Object
            Public BirthDate As Object
            Public HireDate As Object
            Public Address As Object
            Public City As Object
            Public Region As Object
            Public PostalCode As Object
            Public Country As Object
            Public HomePhone As Object
            Public Extension As Object
            Public Photo As Object
            Public Notes As Object
            Public ReportsTo As Object
            Public PhotoPath As Object
            Public Employees As Object
            Public EmployeeTerritories As Object
            Public Orders As Object
            Public Employee As Object
        End Class
    End Class
    Hope this helps [:D]
    Wednesday, November 26, 2008 6:15 PM
  • User-1878671908 posted

    Okay...gonna make one more go on this, and then I think I will have to give up.  I am not seeming to get where I need to with this, and I am sure it is because I do not yet have enough knowledge to know what I am doing.

    Here is what I have:

    Three tables

    1 - Series_Master (this holds my product numbers)

    2 - Series_Master_Best_Cost (this holds data about pricing on my products)

    3 - User_Master (this holds information on which user is associated with which ID number - this is the one that I am trying to get to sort when displaying the Series_Master_Best_Cost table)

    When I click on Series_Master_Best_Costs on the default page, it takes me to my Series_Master_Best_Cost table, with two drop downs on the top.

    1 - Series_Master

    2 - User_Master

    I really need to get rid of the first one as it does nothing for me, but for now, was ONLY trying to sort the User_Master list.

    In my App_Code folder, I created a new .vb file called 'Series_Master_Best_Cost.vb' to place my code in (the code that has been provided here on this forum).

    This is the contents of that file:

    Imports Microsoft.VisualBasic
    Imports System.Web.DynamicData
    Imports System.ComponentModel
    Imports System.ComponentModel.DataAnnotations

    '<MetadataType(GetType(Series_Master_Best_Cost))> _
    <DisplayColumnAttribute("USER_NAME", "USER_NAME", False)> _
    Partial Public Class Series_Master_Best_Cost
        Public Class Series_Master_Best_CostMD
            Public Series_Master_Best_Cost_ID As Object
            Public Series_Master_ID As Object
            Public Best_Cost_Value As Object
            Public Stack_Height As Object
            Public Date_Entered As Object
            Public Date_Modified As Object
            Public Entered_By_ID As Object
            Public Modified_By_ID As Object
        End Class
    End Class

    *Note I have commented out the MetadataType line, but made no difference.  I still do not get a sorted list.

     In 'DisplayColumnAttribute', I attempted to use "User_Name", "User_Master_ID", "User_ID" and "Entered_By_ID"...none made a difference.

    My USER_MASTER table has the following Columns:

    1 - USER_MASTER_ID

    2 - USER_NAME

    3 - FIRST_NAME

    4 - LAST_NAME

    5 - USER_ID

    Entered_By_ID in the Series_Master_Best_Cost table matches User_Master_ID in the User_Master table.

    I thought at first that it might be that my file name needed to be "Series_Master_Best_Costs.vb", plural like the other places, which didn't really seem to be correct, but I tried it anyway and it did not make anything happen either.

    Any further assistance would be greatly appreciated.

    Sorry to seem so lost, but I am... :-)

    Hope everyone had a good holiday!

    Monday, December 1, 2008 2:17 PM
  • User-330204900 posted

    Sorry you are struggling with this do you want me to send you a working example using VB and Northwind DB?

    Monday, December 1, 2008 5:11 PM
  • User-1878671908 posted

    That might be helpful.  I was hoping that I might have provided enough information to have discerned where I might have missed out.  However, a working example would also be very helpful I think.

    I sent you a private message with my email address so I wouldn't have to post in here.

    Thanks, Ann

    Monday, December 1, 2008 5:17 PM
  • User-1878671908 posted

    Oooo-Kay...now that I have been able to see the working version, I discovered the one thing that was NOT in the information on how to make this work...

    In the "DataClasses.dbml" file, you have to create an association for the table of the dropdown that you want to sort.

    In my case, since I was trying to make the "User_Name" be sorted in alphabetical order,  I had to create an association on my "User_Master" table.

    You actually select that table for both Child and Parent, and then select the field that you need sorted for each of those.

    When it actually creates the Association and you go to look at the Child and Parent properties, it shows that the:

    • Child Property is "User_Masters" (The plural name given by Dynamic Data)
    • Parent Property is "User_Master"
    • Participating Properties is "User_Master.User_Name -> User_Master.User_Name" (The name of the field that you want it sorted on.)

    And in my new .vb file, I had to write it as the following:

    Imports Microsoft.VisualBasic
    Imports System.Web.DynamicData
    Imports System.ComponentModel
    Imports System.ComponentModel.DataAnnotations

    <MetadataType(GetType(USER_MASTER.USER_MASTERMD))> _
    <DisplayColumn("USER_NAME", "USER_NAME", False)> _
    Partial Public Class USER_MASTER
        Public Class USER_MASTERMD
            Public USER_MASTER_ID As Object
            Public USER_NAME As Object
            Public FIRST_NAME As Object
            Public LAST_NAME As Object
            Public FULL_NAME As Object
            Public FACILITY_ID As Object
            Public TITLE_ID As Object
            Public DEPARTMENT_ID As Object
            Public ACTIVE As Object
            Public ASSOCIATE_NUMBER As Object
            Public ENTERED_BY_ID As Object
            Public DATE_ENTERED As Object
            Public USER_ID As Object
            Public DATE_WRITE As Object
            Public DATE_HIRE As Object
            Public BIRTH_MONTH As Object
            Public BIRTH_DAY As Object
            Public DATE_TERMINATED As Object
            Public PLANT_ID As Object
        End Class
    End Class

    It is important to note that your partial class needs to be the table that holds the key that you want sorted, not the page of the table that you want it displayed on!  While this may be obvious to some who are more experienced, for someone who is a bit more of a novice, it was not obvious...and even more so...it most certainly was not obvious that I needed to create that association in the "DataClasses.dbml" file.  That association in conjunction with the partial class was the key to making this work!

    Thank you so much for the help!  Having a working example that I could look at and see what was going on in the actual files made all the difference in the world!!!

    Ann

    Tuesday, December 2, 2008 10:37 AM
  • User-330204900 posted

    Are you saying that there was no relationship in you model?

    Wednesday, December 3, 2008 5:17 AM
  • User-1878671908 posted

     I am saying that the relationships between my tables were all there, but that I was not aware that to make this fix work, you had to create an ADDITIONAL relationship, which was not required previously.

    Wednesday, December 3, 2008 12:41 PM
  • User-330204900 posted

    Sorry Ann I'm not sure I understand as I've never had to add a relationship to make any of my models work [:(]

    Wednesday, December 3, 2008 6:58 PM
  • User-1878671908 posted

    I do not know.  What I do know is that the relationship that referred back to itself (on your example it was the Employee table) was not automatically created during this process.  I had to manually add it to the "DataClasses.dbml" layout by creating a new association for my table.  It was ONLY after adding this association that my sorting worked.

    I wish you could include screen shots on here, as that would make it easier to explain.

    If you go to the project you sent me and look at the "DataClasses.dbml" page, you will see a self-referencing association on your Employee table.  That is the one I had to add to mine to make it work.

    If you did not create it, I am unsure of how it got there.  It was not automatically generated for my project.

     Regardless, it was the key to making the sorting of the datalist work for me...and now it is PERFECT!!!

     Thank you again for your assistance!

     Ann

    Thursday, December 4, 2008 9:54 AM
  • User-330204900 posted

    No problem it's good to know you got it working and it's not something wierd stoppint it. [:D]

    Thursday, December 4, 2008 6:25 PM