This is a migrated thread and some comments may be shown as answers.

Applying default filter on initial load - cannot be applied

5 Answers 214 Views
Grid
This is a migrated thread and some comments may be shown as answers.
tomas
Top achievements
Rank 1
tomas asked on 25 Feb 2009, 10:34 PM
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


5 Answers, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 27 Feb 2009, 02:06 PM
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.
0
tomas
Top achievements
Rank 1
answered on 03 Mar 2009, 02:32 PM
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
0
Accepted
Iana Tsolova
Telerik team
answered on 06 Mar 2009, 09:58 AM
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.
0
sameer
Top achievements
Rank 1
answered on 24 Jul 2011, 10:19 AM
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

0
OfficeBooks Team
Top achievements
Rank 1
answered on 24 Feb 2012, 01:13 AM
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
Tags
Grid
Asked by
tomas
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
tomas
Top achievements
Rank 1
sameer
Top achievements
Rank 1
OfficeBooks Team
Top achievements
Rank 1
Share this question
or