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

RadGrid Filtered DataSource

7 Answers 258 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Roger Barnes
Top achievements
Rank 1
Roger Barnes asked on 01 Jul 2008, 08:35 PM


I'm new to using Rad Controls.

We're using the latest version 2008.1 619 of Asp.net Ajax controls.

In my NeedDataSource event, after retrieving my DataTable I filter the data and set my Grid's datasource to the Filter DV, but it's not filtered.

Excerpt, 

dv = dtFast.DefaultView

dv.RowFilter =

"buot_BaseUnitID = buot_BareFanBaseUnitID"

Me.rgFast.DataSource = dv

dv is filtered, DT has 248 rows, DV has 182
but my grid is still showing all 248 rows.

What am I missing?



7 Answers, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 02 Jul 2008, 11:17 AM
Hi Roger,

This should not be the case.
This is demonstrated in the sample application attached to this message.
Let me know if I am leaving something out.

Best wishes,
Yavor
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Roger Barnes
Top achievements
Rank 1
answered on 03 Jul 2008, 04:54 PM

dv = dtFast.DefaultView

dv.RowFilter =

"buot_BaseUnitID = buot_BareFanBaseUnitID"

Me.rgFast.DataSource = dv


The above works, however

dv.Rowfilter = nothing, will cause the grid to no longer be filtered

Or if you have two grid and one data source

dv.rowfilter = "ABC"
Grid1.datasource = dv

dv.Rowfilter = "xyz"
Grid2.Datasource = dv

Grid1 and Grid2 will show the results of the last filter

I worked around it by making a copy of my datsource, dt.copy



0
Rosen
Telerik team
answered on 07 Jul 2008, 08:33 AM
Hello Roger,

This behavior is expected. In the code similar to this:

            DataTable dt = GetDataTable();  
 
            dt.DefaultView.RowFilter = "Col2 = 'desc_1' ";  
            RadGrid1.DataSource = dt.DefaultView;  
 
 
            dt.DefaultView.RowFilter = "Col2 = 'desc_2' ";  
            RadGrid2.DataSource = dt.DefaultView;  
 
            RadGrid1.Rebind();  
            RadGrid2.Rebind(); 

As the DataView object is passed by reference when the first grid is bound the DataView's rowfilter is already changed to the second value. Therefore in order to achieve your goal you should bind each grid right after the assignment of the datasource. Similar to this:

            DataTable dt = GetDataTable();     
    
            dt.DefaultView.RowFilter = "Col2 = 'desc_1' ";     
            RadGrid1.DataSource = dt.DefaultView;     
 
            RadGrid1.Rebind();   
    
            dt.DefaultView.RowFilter = "Col2 = 'desc_2' ";     
            RadGrid2.DataSource = dt.DefaultView;    
                
            RadGrid2.Rebind();    
 


Kind regards,
Rosen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Roger Barnes
Top achievements
Rank 1
answered on 07 Jul 2008, 03:54 PM

I tried your suggestion, which didn't work.

My main grid is bound in NeedDataSource, which seems to be filtered as expected.

In the itemdatabound event of the main Grid, I am dynamically adding a grid to a ToolTip and binding it, which is a subset of data bound to the main grid, which has your suggested rebind, but it's only filtered if I have pageing allowed on the main grid, if I turn off paging on the main grid, all the tooltip grids are identical to the last filter.

I've coded around this issue by making a copy of the datasource in the itemdatabound. 

Any other suggestions?

Roger




 

0
Rosen
Telerik team
answered on 09 Jul 2008, 02:45 PM
Hello Roger Barnes,

You can try clearing the RowFilter value after the assignment of the datasource to the child grids. I have attached a simple page that demonstrate the requested scenario. Please give it a try and see if I'm missing something obvious.

Sincerely yours,
Rosen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Roger Barnes
Top achievements
Rank 1
answered on 09 Jul 2008, 04:39 PM


Although I had already tried your suggestion of clearing the rowfilter, which clears it for all the grids in the tooltips, I tried it again, and got the same results, all grids in the tooltips show all rows.

A couple variations in my situation versus your example, my MainGrid is also filtered, then I conditionally add the Toolip and Grid to a Template column.

The below is the code that adds the tooltip and grid based on my conditions, my workaround is commentd out.

Dim

dataItem As Telerik.Web.UI.GridDataItem = CType(e.Item, Telerik.Web.UI.GridDataItem)

Dim cell As TableCell = dataItem("CellITEMDESC")

Dim RadToolTipMotorDriveCombinations As New RadToolTip

RadToolTipMotorDriveCombinations.TargetControlID =

"lblMotorDriveCombinations1"

RadToolTipMotorDriveCombinations.Position = ToolTipPosition.BottomCenter

RadToolTipMotorDriveCombinations.RelativeTo = ToolTipRelativeDisplay.Element

RadToolTipMotorDriveCombinations.ShowCallout =

True

RadToolTipMotorDriveCombinations.ShowEvent = ToolTipShowEvent.OnClick

RadToolTipMotorDriveCombinations.Skin =

"Telerik"

RadToolTipMotorDriveCombinations.Sticky =

True

RadToolTipMotorDriveCombinations.Width = System.Web.UI.WebControls.Unit.Pixel(600)

RadToolTipMotorDriveCombinations.Title =

"Motor Drive Combinations"

RadToolTipMotorDriveCombinations.ShowDelay = 0

 

Dim rgMotorDriveCombinations As New RadGrid

rgMotorDriveCombinations.Skin =

"Telerik"

rgMotorDriveCombinations.EnableViewState =

False

rgMotorDriveCombinations.AllowSorting =

False

rgMotorDriveCombinations.GridLines = GridLines.Horizontal

rgMotorDriveCombinations.HorizontalAlign = HorizontalAlign.Center

rgMotorDriveCombinations.AutoGenerateColumns =

False

Dim Column As New GridBoundColumn

Column.DataField =

"ITEMNMBR"

Column.HeaderText =

"Item Number"

Column.HeaderStyle.Width = System.Web.UI.WebControls.Unit.Pixel(155)

Column.HeaderStyle.Wrap =

False

rgMotorDriveCombinations.Columns.Add(Column)

Column =

New GridBoundColumn

Column.DataField =

"ITEMDESC"

Column.HeaderText =

"Item Description"

Column.HeaderStyle.Wrap = False

Column.ItemStyle.Wrap =

False

rgMotorDriveCombinations.Columns.Add(Column)

'Dim dtFast As DataTable = CType(Session("dtFast"), DataTable).Copy

Dim dtFast As DataTable = CType(Session("dtFast"), DataTable)

Dim buot_BaseUnitID As Integer = CType(DataBinder.Eval(e.Item.DataItem, "buot_BaseUnitID"), Integer)

'Dim dv As New DataView

'dv = dtFast.DefaultView

'Filter where our bareFanID is equal to our row

'dv.RowFilter = String.Format("buot_BareFanBaseUnitID = {0} and buot_BaseUnitID <> buot_BareFanBaseUnitID", buot_BaseUnitID)

dtFast.DefaultView.RowFilter =

String.Format("buot_BareFanBaseUnitID = {0} and buot_BaseUnitID <> buot_BareFanBaseUnitID", buot_BaseUnitID)

'rgMotorDriveCombinations.DataSource = dv

rgMotorDriveCombinations.DataSource = dtFast.DefaultView.Table

rgMotorDriveCombinations.Rebind()

dtFast.DefaultView.RowFilter =

""

 

RadToolTipMotorDriveCombinations.Controls.Add(rgMotorDriveCombinations)

cell.Controls.Add(RadToolTipMotorDriveCombinations)

0
prakash
Top achievements
Rank 1
answered on 05 Oct 2017, 06:15 AM

string filterexpression = string.Empty;
                    filterexpression = Radgrid_inspectedlist.MasterTableView.FilterExpression;
                    string b = "\"";
                    string[] a = filterexpression.Split(Convert.ToChar(b));
                    int k = 0;
                    foreach (string c in a)
                    {
                        a[k] = c.Replace(b, " ");
                        if ((k % 2) == 0)
                        {
                            a[k] = "";
                        }
                        k++;
                    }
                    a = a.Where(x => !string.IsNullOrEmpty(x)).ToArray();
                    k = 0;
                    string final = "";
                    foreach (string f in a)
                    {
                        if ((k % 2) == 1)
                        {
                            final += " Like '%" + f + "%' And ";
                        }
                        else
                        {
                            final += f;
                        }
                        k++;
                    }

                    final = final.Remove(final.Length - 4);
                    DataRow[] dr = datatable.Select(final);
                    if (dr.Length != 0)
                    {
                        dtInspectedList = dr.CopyToDataTable();
                    }

 

This is only for contains filter

 

 

Tags
Grid
Asked by
Roger Barnes
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Roger Barnes
Top achievements
Rank 1
Rosen
Telerik team
prakash
Top achievements
Rank 1
Share this question
or