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

Update collection on Filter

15 Answers 144 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.
Hakki
Top achievements
Rank 1
Hakki asked on 13 Sep 2012, 12:27 PM
Hello,

I have a grid and a chart bound to a collection called MyData. When I filter that collection on the grid, I want MyData to update with the filtered values.

I have looked at RadDataFilter but it's usability was not at all what we want (takes too much space for one and it's simpler to filter in the grid) so I was wondering if there is anyway the Grid can announce the new filtered data to the MyData collection so the chart can populate with the filtered values.

Thanks.

15 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 13 Sep 2012, 12:32 PM
Hello,

 You can bind the chart to the grid Items collection if you want the chart to respect filtering, sorting, etc.

Regards,
Vlad
the Telerik team

Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

0
Hakki
Top achievements
Rank 1
answered on 13 Sep 2012, 12:45 PM
Great, thanks.
0
Hakki
Top achievements
Rank 1
answered on 13 Sep 2012, 12:59 PM
Hey sorry,

I did:

MySLchart.DataContext = RadGrid.Items;

Filtering the grid doesn't update the chart still.

Thanks for further help.
0
Accepted
Nick
Telerik team
answered on 13 Sep 2012, 01:03 PM
Hello Hakki, 

The correct syntax would be:

MyRadChart.ItemsSource = RadGrid.ItemsSource/Items;

Hope this helps! 

Kind regards,
Nik
the Telerik team

Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

0
Hakki
Top achievements
Rank 1
answered on 13 Sep 2012, 01:15 PM
Ah, yes it worked with RadChart (not the default Silverlight chart).

Thanks a lot guys, great support.

Have a great day,
Hakki.
0
Hakki
Top achievements
Rank 1
answered on 13 Sep 2012, 03:41 PM
Hey guys,

Here is the grid and chart I am working with: http://i230.photobucket.com/albums/ee248/masteratt/telerikchart.png

Is there any way the chart can change it's X-axis based on what the user is grouping the grid by? So if they group by patient, the X-axis will be 331, 555 and label will say Patient.

Also if Patient 331 has multiple Queries Raised, I would want to add them up when being grouped by Patient. It did not do that.

Basically is there an event to let me know grid filtering has changed so I can build logic around it.

Thanks.
0
Vlad
Telerik team
answered on 14 Sep 2012, 05:25 AM
Hi,

 If you bind the chart to the grid Items collection as I already suggested you this will be handled automatically. 

Greetings,
Vlad
the Telerik team

Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

0
Hakki
Top achievements
Rank 1
answered on 14 Sep 2012, 09:36 AM
I know, I thought it would as it made sense for it to but I am obviously missing something.

Please have a look at my code:

//under InitializeComponent
RadGrid.ItemsSource = MyData;

Then setting the chart:

var seriesMapping = new SeriesMapping { LegendLabel = "Query Raised" };
                               seriesMapping.ItemMappings.Add(new ItemMapping("QueryRaisedColumn", DataPointMember.YValue));
                               //seriesMapping.ItemMappings.Add(new ItemMapping("PatientColumn", DataPointMember.XCategory));
                               seriesMapping.SeriesDefinition = new StackedBarSeriesDefinition { ShowItemLabels = false };
 
                               var seriesMapping2 = new SeriesMapping { LegendLabel = "Query Resolved" };
                               seriesMapping2.ItemMappings.Add(new ItemMapping("QueryResolvedColumn", DataPointMember.YValue));
                               //seriesMapping2.ItemMappings.Add(new ItemMapping("PatientColumn", DataPointMember.XCategory));
                               seriesMapping2.SeriesDefinition = new StackedBarSeriesDefinition { ShowItemLabels = false };
 
                               var seriesMapping3 = new SeriesMapping { LegendLabel = "Query Outstanding" };
                               seriesMapping3.ItemMappings.Add(new ItemMapping("QueryOutstandingColumn", DataPointMember.YValue));
                               //seriesMapping3.ItemMappings.Add(new ItemMapping("PatientColumn", DataPointMember.XCategory));
                               seriesMapping3.SeriesDefinition = new StackedBarSeriesDefinition { ShowItemLabels = false };
 
                               MyRadChart.ItemsSource = RadGrid.Items;
                               MyRadChart.DefaultView.ChartArea.AxisY.AutoRange = false;
                               MyRadChart.DefaultView.ChartArea.AxisY.Step = 1;
 
                               MyRadChart.SeriesMappings.Add(seriesMapping);
                               MyRadChart.SeriesMappings.Add(seriesMapping2);
                               MyRadChart.SeriesMappings.Add(seriesMapping3);

I commented out the Xcategory as I thought not setting it might allow the itemsource to change it but no dice.


Ungrouped: http://i230.photobucket.com/albums/ee248/masteratt/telerik1.png

Grouped: http://i230.photobucket.com/albums/ee248/masteratt/telerik2.png

For the grouped, I want X axis to become two (one for each centre) and the YValue to add up ALL the queries resolved/raised/outstanding in that centre.


 Thanks for helping me achieve this!
0
Vlad
Telerik team
answered on 14 Sep 2012, 09:59 AM
Hi,

 You need to bind ItemsSource to Items instead simple assignment. 

Greetings,
Vlad
the Telerik team

Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

0
Hakki
Top achievements
Rank 1
answered on 14 Sep 2012, 10:03 AM
Hello and thanks for the prompt reply.

I am however not sure what you mean, I thought I was already doing that with this line:

MyRadChart.ItemsSource = RadGrid.Items;

Can you elaborate and maybe code up a quick example using my code above.

Much appreciated.


0
Vlad
Telerik team
answered on 14 Sep 2012, 10:08 AM
Hi,

 I strongly suggest you to check MSDN for more info about Binding:
http://msdn.microsoft.com/en-us/library/system.windows.data.binding(v=vs.95).aspx 

Kind regards,
Vlad
the Telerik team

Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

0
Hakki
Top achievements
Rank 1
answered on 14 Sep 2012, 12:01 PM
From what I understand what I did should do it is what I am confused about. Here I did it in XAML:

<telerikChart:RadChart x:Name="MyRadChart" Margin="8,297,6,39" telerik:StyleManager.Theme="Metro"
                                   ItemsSource="{Binding ElementName=RadGrid, Path=Items}" />

Isn't that right? If wrong, how?

Again, the chart updates with the grid's filtered data fine to an extend but not to my specific needs (see this post above).

I feel this got more confusing than it needed to, apologies...However further help is much appreciated. Some examples perhaps?
0
Vlad
Telerik team
answered on 19 Sep 2012, 05:54 AM
Hi,

 You can check the attached project for reference. 

Regards,
Vlad
the Telerik team

Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

0
Hakki
Top achievements
Rank 1
answered on 19 Sep 2012, 09:40 AM
Thanks for that Vlad but I made that part work fine few posts above :)

There is a misunderstanding as to what I am now asking I think. The thread title is now sorted and I guess I should have made a new thread with this new query but here are the functions that are missing from that:

Please take a look at this grid/chart: http://i230.photobucket.com/albums/ee248/masteratt/telerikNoGroup_zps982dffc6.png

Now when I group it by Centre. I want Centre 1 to have 3 Query Outstanding and 3 Query Raised (i.e: adding the columns up in that centre as it was grouped by it) so the stack bar displays accurate information based on grouping.

Where as now it doesn't display it very accurately after I group it: http://i230.photobucket.com/albums/ee248/masteratt/telerikGroup_zpsc0123996.png
As you can see it doesn't add up the query numbers for per centre.

And if I group by Patient, I would want the axis to become 555, 331, 666 (which it doesn't) and again adding the Query columns up based on patient and so on.

The way you worked binding in your example project is identical to how I did so I can confirm that code does not provide the functionality I am asking for here.

If you can provide a reference project (or link to help files) that helps me achieve what I asked for here, it will be immensely appreciated.

Sorry for not creating a separate thread for it (perhaps I should now?), it caused unnecessary confusion but further help would be appreciated.

Thanks in advance.
0
Petar Marchev
Telerik team
answered on 21 Sep 2012, 10:52 AM
Hello Hakki,

Yes I would ask you to open a new thread and explain your requirements there. This is because we are trying to keep different issues in different threads as it eases the communication process. I have anyway attached a simple project that demonstrates how grouping can work between the grid view and chart, but this is only to give you a head start. Open a new thread and we will do our best to assist you.

Greetings,
Petar Marchev
the Telerik team

Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

Tags
GridView
Asked by
Hakki
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Hakki
Top achievements
Rank 1
Nick
Telerik team
Petar Marchev
Telerik team
Share this question
or