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

[Solved] ItemsSource of gridview after apply column filter

9 Answers 422 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
luke
Top achievements
Rank 1
luke asked on 04 Nov 2010, 12:18 PM
Hi, i would like to get itemsource of radgridview after filtering it by filter column, but its in radgridview.ItemsSource there is still initial data isntead of filtered. Is there any other propery or solution which i can get filtered itemssource?

thanks in advance

9 Answers, 1 is accepted

Sort by
0
Accepted
Veselin Vasilev
Telerik team
answered on 04 Nov 2010, 12:23 PM
Hi Łukasz Hutyra,

You can use the Items property of RadGridView.

Greetings,
Veselin Vasilev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
luke
Top achievements
Rank 1
answered on 04 Nov 2010, 12:39 PM
thanks, its solved my problem.
0
Irene
Top achievements
Rank 2
answered on 10 Nov 2010, 12:41 AM
Hi,

I have a similar problem, but I'd like to get filtered (and/or sorted) rows for the entire grid, not only visible page. Items property contains only visible items, ItemsSource - initial collection bound to a grid, neither sorted, nor filtered.

Thank you,

Irene
0
Vlad
Telerik team
answered on 10 Nov 2010, 08:08 AM
Hello,

Can you post more info how the grid is bound (and paged) at your end? If this is server-side paging you will unable to get the other items since they are not available. 

Regards,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Irene
Top achievements
Rank 2
answered on 10 Nov 2010, 06:15 PM

Thank you for a quick reply. The grid is bound to the "GridData" -Telerik DataTable (the "replacement" of ADO.NET DataTable which was graciously created by Vladimir Enchev from Telerik) All the data is fully downloaded from the server before binding to the grid. Here is XAML:

 

<axceler:xcGridView x:Name="grdData" AutoGenerateColumns="True"    SelectionMode="Extended"
                                 AutoExpandGroups="True" CanUserDeleteRows="False" CanUserInsertRows="False" ItemsSource="{Binding Path=GridData, Mode=OneWay}" DataLoadMode="Asynchronous"
                                 ScrollViewer.VerticalScrollBarVisibility="Auto"  AlternationCount="2"  CanUserSelect="False"  Visibility="Collapsed"  
                                 MaxHeight="500" RowIndicatorVisibility="Collapsed">
                            <i:Interaction.Triggers>
                                <i:EventTrigger EventName="SelectionChanged">
                                    <cmd:EventToCommand PassEventArgsToCommand="True"
                                                    Command="{Binding Path=GridSelectionChangedCommand, Mode=OneWay}" />
                                </i:EventTrigger>
                            </i:Interaction.Triggers>
                            <telerik:RadGridView.Columns>
                                <telerik:GridViewDataColumn Header="{Binding Path=xcUIResource.Selected, Source={StaticResource LocalizedStrings }}" DataMemberBinding="{Binding Selected, Mode=TwoWay}" UniqueName="Select" TextAlignment="Center">
                                    <telerik:GridViewDataColumn.CellTemplate>
                                        <DataTemplate>

                                            <CheckBox x:Name="chckSelected"  IsChecked="{Binding Selected,  Mode=TwoWay}" Checked="chckSelected_Checked" />

                                        </DataTemplate>
                                    </telerik:GridViewDataColumn.CellTemplate>

                                </telerik:GridViewDataColumn>

                            </telerik:RadGridView.Columns>
</axceler:xcGridView>
<axceler:xcDataPager x:Name="radDataPager"     PageSize="15"     Source="{Binding Items, ElementName=grdData}" Visibility= "Collapsed"
                                 Margin="0 1 0 10"  />

 

axceler:xcGridView  and axceler:xcDataPager  are subclasses of RadGridView and RadDataPager with no extra functionality added so far.

 

Thanks a lot for looking into this issue.

Irene

 

 

0
Veselin Vasilev
Telerik team
answered on 15 Nov 2010, 06:15 PM
Hi Irene,

To my regret there is no direct way to get the paged filtered data in RadGridView. Can you tell us at what stage you want to take that data? Is it on button click or something else?

One of the possible solutions would be to work directly with your data source. You can convert it to queryable by calling the AsQuearyable() method and then add the RadGridView's FilterDescriptors collection to its Where clause. Similarly you can add the SortDescriptors to the Sort method and now you will have all the data that match these criteria.

Let me know if this helps.

Best wishes,
Veselin Vasilev
the Telerik team
See What's New in RadControls for Silverlight in Q3 2010 on Tuesday, November 16, 2010 11:00 AM - 12:00 PM EST or 10:00 PM - 11:00 PM EST: Register here>>
0
Irene
Top achievements
Rank 2
answered on 15 Nov 2010, 06:42 PM

Thank you for your answer!

 

Yes I want the data on button click event. I am using the grid data as a feed to a chart and for users would be natural to expect that after sorting and filtering the chart will show sorted and filtered data. I was thinking about using queryable source, but thought I could have a simple way out  :-).

 

 

Thanks,

 

Irene

0
Alex
Top achievements
Rank 1
answered on 18 Nov 2010, 09:40 PM
Irene - You can probably get by with something like this. It may not be as performant as the solution Veselin provided, but the implementation might be simpler:

// setup a dummy dataset
DataSet ds = new DataSet();
DataTable dt = new DataTable();
  
// add the columns you want from the radgrid
dt.Columns.Add(new DataColumn("ColumnName1"));
dt.Columns.Add(new DataColumn("ColumnName2"));
dt.Columns.Add(new DataColumn("ColumnName3"));
// etc
  
ds.Tables.Add(dt);
  
int currentPage = radgrid.CurrentPageIndex;
  
// disable paging and rebind so you get all items
radgrid.AllowPaging = false;
radgrid.Rebind();
  
foreach (GridItem item in radgrid.MasterTableView.Items)
{
    if (item is GridDataItem)
    {   // import the row to the dummy dataset
        dt.ImportRow((item.DataItem as DataRowView).Row);
    }
}
  
// re-enable paging
radgrid.AllowPaging = true;
radgrid.CurrentPageIndex = currentPage;

At that point your dataset will contain the filtered and sorted data from the radgrid. It's kind of hacky, though.
0
Irene
Top achievements
Rank 2
answered on 01 Dec 2010, 08:23 PM

Thank you, Alex.

 

It seems like your code pertains to ASP.NET, not Silverlight....

 

Irene

Tags
GridView
Asked by
luke
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
luke
Top achievements
Rank 1
Irene
Top achievements
Rank 2
Vlad
Telerik team
Alex
Top achievements
Rank 1
Share this question
or