<syncfusion:SfDataGrid Name="sfgrid" FilterChanged="sfgrid_FilterChanged" AllowDraggingColumns="True" AllowEditing="True" AllowFiltering="True" ItemsSource="{Binding OrderList}" ShowGroupDropArea="True" /> |
private void sfgrid_FilterChanged(object sender, Syncfusion.UI.Xaml.Grid.GridFilterEventArgs e) { ObservableCollection<OrderInfo> order = new ObservableCollection<OrderInfo>(); var records = (sender as SfDataGrid).View.Records; foreach (RecordEntry record in records) order.Add(record.Data as OrderInfo); chart.Series.Clear(); ColumnSeries series = new ColumnSeries() { ItemsSource = order, XBindingPath = "ProductName", YBindingPath = "Price", }; chart.Series.Add(series); } |
Hi,thanks for the reply. I see that you showed me the same sample I refered in my question (https://help.syncfusion.com/wpf/sfdatagrid/filtering#getting-the-filtered-records). I see that you have model class OrderInfo and that part is clear
.My problem is that ItemsSource of the data grid is DataSet so no class is involved.
Let's say this is my DataSet which I populate the data grid.
public void FillDataSet()
{
DataTable dtArticles = new DataTable("Articles");
dtArticles.Columns.Add("id");
dtArticles.Columns.Add("name");
dtArticles.Columns.Add("idgroup");
dtArticles.Rows.Add(1, "Cola", 1);
dtArticles.Rows.Add(2, "Pizza", 2);
dtArticles.Rows.Add(3, "Steak", 2);
DataTable dtGroups = new DataTable("Groups");
dtGroups.Columns.Add("idgroup");
dtGroups.Columns.Add("groupname");
dtGroups.Rows.Add(1, "Drink");
dtGroups.Rows.Add(2, "Food");
ds = new DataSet("gastronomy");
ds.Tables.Add(dtArticles);
ds.Tables.Add(dtGroups);
}
When I filter the data inside the sfDataGrid, let's say I want to see only Coca Cola inside the graph, this is where I have the problem.
I also attached Visual Studio project file where you can see the problem.
1. When I run this test application I get this:Chart is empty.
When I press ItemSource button to fill the chart I get this:
Which is also great. But now I make a filter to show me only Cola
My grid now looks like:
And now the problem, how to translate this filtered grid data to chart so that I only see Cola, but not with model class because I don't have it.
Best regards
private void btnItemSource_Click(object sender, RoutedEventArgs e) { // This part links data source diretly to the chart from DataTable sfChart1.Series.Clear(); sfChart1.Header = "TEST header"; CategoryAxis primaryAxis = new CategoryAxis(); primaryAxis.Header = "Article Name"; //primaryAxis.ShowTrackBallInfo = true; sfChart1.PrimaryAxis = primaryAxis; NumericalAxis secondaryAxis = new NumericalAxis(); secondaryAxis.Header = "Group"; sfChart1.SecondaryAxis = secondaryAxis; ColumnSeries series1 = new ColumnSeries(); // Here I'm converting DataView from grid to DataTable DataTable myTable; DataView MyView; //// Bind dataGridView to DataView. MyView = (DataView)sfDataGrid2.ItemsSource; // Bind DataView to Table. myTable = (DataTable)MyView.ToTable(); series1.ItemsSource = myTable; series1.XBindingPath = "Name"; series1.YBindingPath = "idgroup"; series1.ShowTooltip = true; sfChart1.Series.Add(series1); } |
Thank you very much, it was so simple:
from
myTable = (DataTable)MyView.Table;
to
myTable = (DataTable)MyView.ToTable();
Again thank you for your time.