Applying default filter on initial load - cannot be applied

6 posts, 1 answers
  1. tomas
    tomas avatar
    137 posts
    Member since:
    Sep 2012

    Posted 25 Feb 2009 Link to this post

    Hello.

    I am trying to set up the grid default filter, but i cannot. Your example is wrong.

    Why?

    I am binding the grid using the NeedDataSource in the same way as you are writing in Advanced Data-binding (using NeedDataSourceEvent).

    I can read:

    If you are binding the grid using the NeedDataSource event, you can set the initial filter in the NeedDataSource event handler and omit the call to the Rebind method. The code for setting the filter must still be placed inside an if statement that checks that Page.IsPostBack is False.

    No, It cannot be done.

    Reason?

    Grid has no columns at this time. RadGrid1.MasterTableView.GetColumnSafe("") always returns null. (although datasource has already be assigned).

    I also don't need to call  RadGrid1.MasterTableView.FilterExpression = "SQL expression" because my data has been already filtered. I am using SQL SERVER power to do that and I think that everybody must prefer server technology for this type of task.

    So I must use PreRender event, but:

    (!)

    I must call this.RadGrid1.Rebind(); If I don't, the filter function is preselected, but filter value TextBox is empty !!!!

    What does Rebind do really? MY grid has thousands of rows. Is it really needed to call rebind because of one value needs to be inserted in a TextBox? The filter function is preselected, so why TextBox is empty?

    Thank you very much.

    Tom


  2. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3375 posts
    Member since:
    Sep 2012

    Posted 27 Feb 2009 Link to this post

    Hi tomas,

    Straight to your questions:
    Calling the Rebind() method of RadGrid would explicitly fire the NeedDataSource event. And further information on the grid lifecycle is available in the below articles:

    http://www.telerik.com/help/aspnet-ajax/grdeventsequence.html
    http://www.telerik.com/help/aspnet-ajax/grdcommandsthatinvokerebindimplicitly.html

    In order appropriate text to be set in the filter textBox and the corresponding filter function to be selected, as it is done in this help topic:
     

    protected void RadGrid1_PreRender(object sender, System.EventArgs e)  
    {  
     if (!Page.IsPostBack)  
     {  
       RadGrid1.MasterTableView.FilterExpression = "([Country] LIKE \'%Germany%\') ";  
       GridColumn column = RadGrid1.MasterTableView.GetColumnSafe("Country");  
       column.CurrentFilterFunction = GridKnownFunction.Contains;  
       column.CurrentFilterValue = "Germany";  
       RadGrid1.MasterTableView.Rebind();  
     }  
    }  

    Give it a try and let me know how it goes.

    All the best,
    Iana
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.

  3. tomas
    tomas avatar
    137 posts
    Member since:
    Sep 2012

    Posted 03 Mar 2009 Link to this post

    Hello Lana and all Telerik team.

    I know your sample. 

    Please, answer me, why my grid does not work, as you are writing.

    ---
    If you are binding the grid using the NeedDataSource event, you can set the initial filter in the NeedDataSource event handler and omit the call to the Rebind method. The code for setting the filter must still be placed inside an if statement that checks that Page.IsPostBack is False.

    I want to omit the call to the Rebind method. But It cannot be done.

    Reason?

    Grid has no columns at this time. RadGrid1.MasterTableView.GetColumnSafe("") always returns null. (although datasource has already be assigned).
    ---

    Also you are writing:

    Calling the Rebind() method of RadGrid would explicitly fire the NeedDataSource event.

    It seems to me, that this is not correct.

    I am calling rebind in the PreRender method. NeedDataSource method is not called again.

    Thank you Tom

  4. Answer
    Iana Tsolova
    Admin
    Iana Tsolova avatar
    3375 posts
    Member since:
    Sep 2012

    Posted 06 Mar 2009 Link to this post

    Hello tomas,

    The GetColumnSafe method could return null in case you are using auto generated column. This is because the auto generated column are created on later stage, after the NeedDataSource event is executed. Therefore you need to rebind the grid on grid PreRender event to apply the initial filer expression when AutoGenerateColumns property is set to true.

    I will updated the help topic in question according to the upper information.

    Please excuse us for the inconvenience.


    Best wishes,
    Iana
    the Telerik team


    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.

  5. sameer
    sameer avatar
    2 posts
    Member since:
    Apr 2011

    Posted 24 Jul 2011 Link to this post

    Secenario:
        EntityDataSource
        RadGrid
        

    <

    telerik:RadGrid ID="rgView" runat="server" AllowFilteringByColumn="True" AllowPaging="True" AllowSorting="True" CellSpacing="0" GridLines="None" ShowGroupPanel="True" AutoGenerateColumns="False"  DataSourceID="edsEst" onprerender="rgView_PreRender"

    Returns the following error while trying to set the initial filter for Grid in the Grid_PreRender event (Version Q2 2011):

    could not be resolved in the current scope or context. Make sure that all referenced variables are in scope, that required schemas are loaded, and that namespaces are referenced correctly

  6. OfficeBooks Team
    OfficeBooks Team avatar
    6 posts
    Member since:
    Nov 2010

    Posted 23 Feb 2012 Link to this post

    Hi, after some time I found a solution for this problem

    Disable the radgrid property EnableLinqExpressions

    This will allow to find the missing fields on filter

Back to Top