locked
Only show a subset of rows for a table RRS feed

  • Question

  • User1840112551 posted

    Hello Experts! In my dynamic data entities website, I only want a subset of rows to show for a table instead of the entire table. For e.g. in a table of employees, instead of all employees, I only want "WHERE DEPT_NO > 3000". The framework is doing a great job in showing all the foreign keys along with the basic table data.

    Do I have to write a List.aspx from scratch in CustomPages > Table_Name folder, or is there a simpler way of doing this?

    Monday, January 16, 2012 11:54 AM

Answers

  • User1840112551 posted

    The simplest method I have found for this is change the code behind for list.aspx.cs. Check the table name, if its the same table for which you want to add the where clause, add it right there to the EntityDataSource control.

            protected void Page_Init(object sender, EventArgs e)
            {
                table = DynamicDataRouteHandler.GetRequestMetaTable(Context);
                GridView1.SetMetaTable(table, table.GetColumnValuesFromRoute(Context));
                GridDataSource.EntityTypeFilter = table.EntityType.Name;
                if(table.Name.Equals("Employee")
                    GridDataSource.Where = "it.DEPT>3000";
            }
    
    
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, January 19, 2012 9:51 AM
  • User-330204900 posted

    yes that is sort of what I do but I tend to use a filter and make it hidden then I can control it with metadata.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, January 19, 2012 11:05 AM

All replies

  • User-330204900 posted

    Hi Greatbear, you can use a filter see Dynamic Data 15 Custom Filters or you can add a custom filter via the QueryExntender.

    Tuesday, January 17, 2012 12:43 PM
  • User1840112551 posted

    steve, could you please check the link? i get the following message:

    The page you are looking for is not available...
                If you typed in the URL yourself, please double-check the spelling.
    If you got here from a link within our site, please Contact Us.

    Tuesday, January 17, 2012 2:09 PM
  • User-330204900 posted

    sorry about that I just fixed it, the ASP.Net Editor sometimes crops the URLs, it's a long standing issue and it still gets me when I am in a hurry :)

    Tuesday, January 17, 2012 2:19 PM
  • User1840112551 posted

    thanks! i just tried from package manager console and got this:

    PM> install-package NotAClue.DynamicData.CustomFilters

    'AjaxControlToolkit (≥ 4.1.50508)' not installed. Attempting to retrieve dependency from source...

    Done.

    'NotAClue.DynamicData.Extensions (≥ 1.2.1)' not installed. Attempting to retrieve dependency from source...

    Done.

    Successfully installed 'AjaxControlToolkit 4.1.51116'.

    Successfully installed 'NotAClue.DynamicData.Extensions 1.2.1.1'.

    Successfully installed 'NotAClue.DynamicData.CustomFilters 1.2.1.2'.

    Successfully added 'AjaxControlToolkit 4.1.51116' to Models.

    Successfully added 'NotAClue.DynamicData.Extensions 1.2.1.1' to Models.

    Install-Package : You cannot call a method on a null-valued expression.

    At line:1 char:16

    + install-package <<<<  NotAClue.DynamicData.CustomFilters

        + CategoryInfo          : NotSpecified: (:) [Install-Package], RuntimeException

        + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageCommand

    PM>

    Tuesday, January 17, 2012 2:22 PM
  • User1840112551 posted

    looks like the package did get installed as i can do "using NotAClue.ComponentModel.DataAnnotations;"

    but i dont know how to use the filter. i basically want to add a where clause to a table.

     

    if i try to apply a Filter attribute on a column, i get this compile error:

    Assembly generation failed -- Referenced assembly 'NotAClue.ComponentModel.DataAnnotations' does not have a strong name

    Tuesday, January 17, 2012 2:42 PM
  • User1840112551 posted

    Finally, im getting an idea of whats going on in the NotAClue assemblies.

    What I was looking for is filtering data on the backend, not frontend.

    There is a particular table, and I need to show only a subset of rows. The subset is decided by me, the developer, not the end-user. Is this possible without having to custom code the List.aspx? Like through a metadata class of the table?

    Tuesday, January 17, 2012 5:04 PM
  • User-330204900 posted

    It all happens at the back end as Linq queries are composable so the still happen on the server. The one issue I have with LINQ i.e. Linq to SQL and EntityFramework there is no easy way to add a filter into the pipline, the closest thing I have seen is WCF RIA Services and DomainService which is not all there at the moment.

    Tuesday, January 17, 2012 6:34 PM
  • User1840112551 posted

    The simplest method I have found for this is change the code behind for list.aspx.cs. Check the table name, if its the same table for which you want to add the where clause, add it right there to the EntityDataSource control.

            protected void Page_Init(object sender, EventArgs e)
            {
                table = DynamicDataRouteHandler.GetRequestMetaTable(Context);
                GridView1.SetMetaTable(table, table.GetColumnValuesFromRoute(Context));
                GridDataSource.EntityTypeFilter = table.EntityType.Name;
                if(table.Name.Equals("Employee")
                    GridDataSource.Where = "it.DEPT>3000";
            }
    
    
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, January 19, 2012 9:51 AM
  • User-330204900 posted

    yes that is sort of what I do but I tend to use a filter and make it hidden then I can control it with metadata.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, January 19, 2012 11:05 AM
  • User1840112551 posted

    Is it possible if you could show me a basic example how your Filters work? I just can't seem to understand how to use them, how/where/which attribute to apply.

    Wednesday, February 1, 2012 3:50 PM
  • User1840112551 posted

    Is is possible if you could share a sample on how to use your Filters. I just cant seem to understand how to use them - how/where/what attribute to use when trying to add WHERE clause to a metatable. Also you mentioned QueryExtender. How do I use that?

    Wednesday, February 1, 2012 3:54 PM
  • User-330204900 posted
    Hi Greatbear, I work up an example for you tomorrow here you go
    [MetadataTypeAttribute(typeof(Order.OrderMetadata))]
    public partial class Order 
    { 
        internal sealed class OrderMetadata 
        { 
            [FilterUIHint("Autocomplete")]        
            public Customer Customer { get; set; } 
        } 
    }
    I had forgotten how simple it is to use them, some work on numeric column such as GreaterThan etc. and some on text column sutch as Contain or StartsWith etc. have fun.
    Wednesday, February 1, 2012 5:02 PM
  • User1840112551 posted

    Sorry I'm just not getting it!

    I was hoping to see an example of the Filter attribute in the NotAClue.ComponentModel.DataAnnotations namespace, not the FilterUIHint is in the System.ComponentModel.DataAnnotations namespace.

    For instance in a table that has Year as a column, I just need rows with Year greater or equal to 2012. Will your filter do something like:

    [Filter(DefaultValue="GreaterThanOrEqual")
    public int Year{ get; set; }

    But where do I set the value to compare against (2012) ?

     

    Wednesday, February 1, 2012 5:25 PM
  • User-330204900 posted
    I dont use the Filter attribute like that all it is used for at the moment is to set the filter order;
    [Filter(Order=2)
    public int Year{ get; set; }
    This only works though if you are using one of my Advanced or Secure MetaModels.
    Thursday, February 2, 2012 4:14 AM
  • User1840112551 posted

    Maybe this article will be useful to someone on filtering rows in a Dynamic Data page:

    http://technet.microsoft.com/en-us/query/dd723646

     

    Friday, February 3, 2012 12:28 PM