Easy DropDownList enabler for CheckBoxColumn

8 posts, 0 answers
  1. nagir
    nagir avatar
    161 posts
    Member since:
    Feb 2007

    Posted 21 May 2007 Link to this post

    Requirements

    RadGrid version

    4.6.0
    .NET version

    1.1
    Visual Studio version

    2002/2003
    programming language

    C#
    browser support

    all browsers supported by RadGrid


     
    PROJECT DESCRIPTION
    This sample project contains class that allows easily (with one line of code) enable DropDownList filter for CheckBoxColumn.

    It can be used in any project and there's no need to add lots of code to Page as it is done in help topic.
    Most important features for me:
    1. Filtering by many columns is supported (it is not the case in the help topic).
    2. DropDownList can be enabled for many columns and many grids.
    3. Reusable among different Pages and Projects.
    4. Simple, documented and extendable  code.
    5. Enabled with single line of code.
    USAGE
    To enable DropDownList filtering with CheckBoxColumn the following steps are required:
    1. Add class (TelerikCheckboxColumnFilteringEnabler.cs) to your project.
    2. Add valid using clause (Argo.Web) and Handle Page_Init event.
    3. Use static method  EnableCheckboxColumnFiltering to enable DropDownList as in sample below.
    private void WebForm1_Init(object sender, System.EventArgs e)  
    {  
        TelerikCheckboxColumnFilteringEnabler.EnableCheckboxColumnFiltering(DemoGrid, "ColumnUniqueID"); 
     
     

    The method requires 2 parameters:
    • RadGrid grid - grid for which it is needed to enable DropDownList.
    • string columnUniqueName - column unique name of the column to enable DropDownList for.
    LIMITATIONS
    1. Currently DropDownList can be enabled only for MasterTableView. No child views are supported.
    2. Filter value of DropDownList is stored in server's Session object. So it can time-out. To override this behavior override SaveData() and LoadData() methods. I would suggest to save it into Page's ViewState object.
    3. Instance of this class must be created AFTER grid is subscribed to NeedDataSource event which is the default behavior in most cases.
    4. Instance of this class should be created (or static method call) inside Page_Init handler.
    5. DropDownList filter items (No filter, Checked, Unchecked) are hard-coded.
    Screenshoot is included in the ZIP archive.
  2. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 22 May 2007 Link to this post

    Hello Dmitriy,

    Thank you for the sample project and the detailed explanation. This is a nice online resources for all members of the Telerik community interested in more generic and portable solution for built-in GridCheckBoxColumn filtering with dropdown list. We appreciate the time you spent to put together the example - 2000 Telerik points goes to your account for the involvement.

    Happy coding and keep posting.

    Best regards,
    Stephen
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. nagir
    nagir avatar
    161 posts
    Member since:
    Feb 2007

    Posted 22 May 2007 Link to this post

    Hi Stephen,

    On the page http://www.telerik.com/client.net/telerik-points.aspx I can see that at least 10000 telerik points members receive for code example.
    I have received 2000 (5 times less than minimal).

    Is my example such useless or there's some mistake?

    Cheers,
    Dima.
  4. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 22 May 2007 Link to this post

    Hello Dmitriy,

    10000 Telerik points are given for one of the top code library projects which are started from scratch from a community member. This is not the minimum amount of points for code library but rather the edge you can reach when posting a sample.
    Since the solution you have implemented has been shown in a raw form as part of an help resource, we have decided to reward you with 2000 Telerik points. After your second post I have spoken with Stephen and several of the RadGrid developers and we have decided to give you additional 1500 Telerik points because of the modularity and easy usage of the custom class through various grids and pages.

    Thank you once again for the participation in this thread and for the time you dedicated to build the demo.

    Best regards,
    Stephen Rahnev,
    Technical Support Director, Telerik

    Instantly find answers to your questions at the new Telerik Support Center
  5. nagir
    nagir avatar
    161 posts
    Member since:
    Feb 2007

    Posted 22 May 2007 Link to this post

    Hello Stephen,

    Thank you for the clarification.
    But I just think that note ">10,000" is a little confusing.
    Maybe for future members for you'd explain that.

    Cheers,
    Dima,
  6. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 22 May 2007 Link to this post

    Hi Dmitriy,

    Below is a quote from the code library general section:

    Besides, the Code Library is a great place to earn extra Telerik points (up to 10,000) which you can use for discounts on future purchases or for cool Telerik merchandise.

    I hope this clarifies everything.

    Best regards,
    Stephen Rahnev,
    Technical Support Director, Telerik

    Instantly find answers to your questions at the new Telerik Support Center
  7. nagir
    nagir avatar
    161 posts
    Member since:
    Feb 2007

    Posted 22 May 2007 Link to this post

    Hi Stephen,

    Yes. It does clarifies everything, but I was looking at Questions & Answers section in my telerik points page.
    Here is quote from there:
    How do I earn my Telerik points? You earn Telerik points simply by using the community tools on our web-site. Every time you interact on our web-site, we will add points to your account.

    Activity                                Points
    Complete your Client.net profile

    1000

    Vote in a poll

    100

    Fill in a survey

    2,500

    Send a testimonial

    1,000

    Make a KB comment

    0-300*

    Send Bug Report

    0-3,000*

    Send Feature Request

    0-3,000*

    Send General Feedback

    0-3,000*

    Send a Client Spotlight

    5,000

    Test a beta product

    >10,000*

    Send a code example

    >10,000*

    Refer friends/colleagues

    15% of their purchases


    As we can see it is mentioned more than 10000 points for code sample.
    But anyway, I just want to notify you about different data on the site.

    Cheers,
    Dima.
  8. nagir
    nagir avatar
    161 posts
    Member since:
    Feb 2007

    Posted 23 May 2007 Link to this post

    BUGFIX. AND operator may stays at the begginging of the filter expression casing invalid filtering behaviour.
    Replace existing method by this one. Important code is bolded:

    1 void SetFilter(string filterValue)  
    2 {  
    3     string startString = string.Format("([{0}] = ", fColumnUniqueName);  
    4     string endString = filterValue + ")";  
    5     string expr = fGrid.MasterTableView.FilterExpression;  
    6     const string andOperator = " AND ";  
    7  
    8     int iStart = expr.IndexOf(startString);  
    9     if (iStart != -1)  
    10     {  
    11         int iPlaceStart = iStart + startString.Length;  
    12         int iEnd = expr.IndexOf(")", iPlaceStart);  
    13         if (filterValue != null)  
    14         {  
    15             // Replace value of the filter  
    16             expr = expr.Remove(iPlaceStart, iEnd - iPlaceStart + 1);  
    17             expr = expr.Insert(iPlaceStart, endString);  
    18         }  
    19         else 
    20         {  
    21             // Remove the filter  
    22             // rStart takes also precending AND operator  
    23             int rStart = iStart > andOperator.Length + 1 ? iStart - andOperator.Length : iStart;  
    24             expr = expr.Remove(rStart, iEnd - rStart + 1);  
    25  
    26             if (iStart == rStart)  
    27             {  
    28                 // No precending AND OP removed.  
    29                 // Assuming that we remove filter from the begginign of the string.  
    30                 // Thus we have to remove post OP  
    31  
    32                 // Assuming "EXPR OP EXPR OP". EXPRs and OPs are separated by space.  
    33                 int space = expr.IndexOf(' ', rStart);  
    34                 if (space != -1)  
    35                     space = expr.IndexOf(' ', space + 1);  
    36                 if (space != -1)  
    37                 {  
    38                     // Two spaces away. Assuming [rStart...space] is an OP  
    39                     expr = expr.Remove(rStart, space - rStart + 1);  
    40                 }  
    41  
    42             }  
    43         }  
    44     }  
    45     else 
    46     {  
    47         // Add new filter if Filter is set  
    48         if (filterValue != null)  
    49         {  
    50             if (fGrid.MasterTableView.FilterExpression != null && fGrid.MasterTableView.FilterExpression != string.Empty)  
    51                 expr += andOperator;  
    52             expr += startString + endString;  
    53         }  
    54     }  
    55     fGrid.MasterTableView.FilterExpression = expr;  
    56
Back to Top