This is a migrated thread and some comments may be shown as answers.
Urgent - Grid Filtering
4 Answers 42 Views
This is a migrated thread and some comments may be shown as answers.
lkeel
Top achievements
Rank 1
lkeel asked on 24 Mar 2010, 05:28 PM
I have a grid that I want to allow the client to filter the data because it is a very clean solution.  The problem is that the grid is pulling all of the data over from the server into the .NET side and then applies the filtering accordingly.  The problem is that there is 10 years worth of history data that is pulling across the network and that is killing performance.  Is there any way to turn the filtering on to filter the data pulled from the server instead of pulling it all then filtering?  Or is there a better way to do this?

4 Answers, 1 is accepted

Sort by
0
Foenix
Top achievements
Rank 1
answered on 24 Mar 2010, 07:58 PM
RadGrid cannot filter data on the database level, so, you have to implement such functionality.
Let's say, you have RadGrid1 on your page. You handle NeedDataSource event to provide some datasource to your grid.
protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e) 
    RadGrid1.DataSource = new SomeDataReader("SELECT * FROM SomeTable"); 
 
To minimize selected data you have to pass correct SQL-request. For example, if the user selected "MyValue" as a filter value for SomeColumn and EqualsTo as a filter function, you should send "SELECT * FROM SomeTable WHERE SomeColumn = ''"
protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e) 
    GridColumn col = RadGrid1.MasterTableView.GetColumnSafe("SomeColumn"); 
    string filterValue = col.CurrentFilterValue; 
 
    string sqlRequest; 
    if (col.CurrentFilterFunction == GridKnownFunction.EqualsTo) 
    { 
        sqlRequest = string.Format("SELECT * FROM SomeTable WHERE SomeColumn ='{0}'", filterValue); 
    } 
 
    RadGrid1.DataSource = new SomeDataReader(sqlRequest); 
Of course, it is very simple code, just to give you an idea how to implement desired functionality.


0
lkeel
Top achievements
Rank 1
answered on 25 Mar 2010, 02:33 PM

But is there a way to use the filters built intothe grid and get the filter desired by the client during the NeedDataSource?  Example workflow:


* Send some amount of data to the grid

* Client changes filter for some column =  value

* NeedDataSource is called and query is changed accordingly

0
Foenix
Top achievements
Rank 1
answered on 25 Mar 2010, 04:26 PM
Are you talking about pre-filtering? If yes, here is a simple solution:

protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)  
{  
    GridColumn col = RadGrid1.MasterTableView.GetColumnSafe("SomeColumn"); 
     
    if (string.IsNullOrEmpty(col.CurrentFilterValue) || (col.CurrentFilterFunction == GridKnownFunction.NoFilter)) 
    { 
        col.CurrentFilterValue = someDefaultValue; 
        col.CurrentFilterFunction = GridKnownFunction.EqualTo; 
    } 
 
    string filterValue = col.CurrentFilterValue;  
 
    string sqlRequest;  
    if (col.CurrentFilterFunction == GridKnownFunction.EqualsTo)  
    {  
        sqlRequest = string.Format("SELECT * FROM SomeTable WHERE SomeColumn ='{0}'", filterValue);  
    }  
  
    RadGrid1.DataSource = new SomeDataReader(sqlRequest);  
}  

Of course, you have to use your own values for CurrentFilterValue and CurrentFilterFunction. And even your own approach to define your filter by default.
0
lkeel
Top achievements
Rank 1
answered on 29 Mar 2010, 09:35 PM
This seems to have me going in the right direction.  I think.
Tags
Grid
Asked by
lkeel
Top achievements
Rank 1
Answers by
Foenix
Top achievements
Rank 1
lkeel
Top achievements
Rank 1
Share this question
or