Problem in loading the RadDomainDataSource dynamically from code behind.

2 posts, 0 answers
  1. SivaPrasad Bevara
    SivaPrasad Bevara avatar
    73 posts
    Member since:
    Oct 2012

    Posted 11 May 2011 Link to this post

    Hi,

    I am using following code for RadDaominDataSource to load RadGridView, RadDataFilter and RadDataPager.

    <telerik:RadDomainDataSource Name="TDomainDataSource"
                                        QueryName="GetData"
                                        AutoLoad="True"
                                        PageSize="10"
                                        Height="0" Width="0"
                                        >
                    <telerik:RadDomainDataSource.DomainContext>
                        <local:TDomainContext></local:TDomainContext>
                    </telerik:RadDomainDataSource.DomainContext>
                    <telerik:RadDomainDataSource.SortDescriptors>
                        <telerik:SortDescriptor Member="ReferenceNumber"></telerik:SortDescriptor>
                    </telerik:RadDomainDataSource.SortDescriptors>
                    <telerik:RadDomainDataSource.FilterDescriptors>
                        <telerik:FilterDescriptor Member="SId" Operator="IsEqualTo" Value="2"></telerik:FilterDescriptor>
                    </telerik:RadDomainDataSource.FilterDescriptors>
                </telerik:RadDomainDataSource>

    <telerik:RadGridView Name="customerGridView" Width="900" Height="360"
                                ItemsSource="{Binding DataView, ElementName=TDomainDataSource}">
    </telerik:RadGridView>
      
    <telerik:RadDataPager x:Name="radDataPager" Width="900" Height="40"
        Source="{Binding DataView, ElementName=TDomainDataSource}" 
    DisplayMode="All"  IsTotalItemCountFixed="True"/>
      
    <telerik:RadDataFilter x:Name="radDataFilter" 
                   Source="{Binding DataView, ElementName=TDomainDataSource}">
    </telerik:RadDataFilter>

    The above code working good.

    Now, I have a chart in the same page and I want populate the grid data, based on the chart item selection.
    So I set the Auto Load property to False and I have implemented the following code in the Item click event to load the data in the Grid.
    I am setting the Filter descriptors of the RadDomainDataSource when we click on the chart item.

    private void TSChartArea_ItemClick(object sender, ChartItemClickEventArgs e)
     {
              SId = ((TransactionsVsSecurityType)e.DataPoint.DataItem).SId;
              TDomainDataSource.FilterDescriptors.Clear(); 
             customerGridView.ItemsSource = null;
              LoadGridView(SId );
    }
      
    private void LoadGridView(int SId)
    {
                Telerik.Windows.Data.FilterDescriptor FD = new Telerik.Windows.Data.FilterDescriptor();
                FD.Member = "SId";
                FD.Operator = Telerik.Windows.Data.FilterOperator.IsEqualTo;
                FD.Value = SId;
                TDomainDataSource.FilterDescriptors.Add(FD);
                  
                TDomainContext TnDomainContext;            
                TnDomainContext = TDomainDataSource.DomainContext as TDomainContext; 
                TnDomainContext.Load<TDTO>(TnDomainContext.GetTransactionsQuery(), new Action<LoadOperation<TDTO>>(LoadGridCompleted), null);
            }
      
            private void LoadGridCompleted(LoadOperation<TDTO> args)
            {
                customerGridView.ItemsSource = args.Entities;
            }

    With the above code, I am able to load the GridView properly, when I click on the Chart Item for first time.
    When I click on another chart item, then it is loading all the records, instead of the records related to the sected SId.

    Please help me in fixing this.

    Regards,
    SivaPrasad.B
  2. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 11 May 2011 Link to this post

    Hello SivaPrasad Bevara,

    Why don't you use QueryParameters instead of doing this complex logic? Add a parameter to the server method, let's call it SId. On the client, add a QueryParameter to the QueryParameter's collection of RadDomainDataSource. Data-bind its Value to something on your ViewModel (DataContext). When the user clicks the chart -- change this property in the ViewModel so that the Binding triggers. Leave AutoLoad to true. In this way, each time the user clicks something, the ViewModel will be updated, the Binding will trigger, the Value of the QueryParameter will change to something new and since AutoLoad is true, RadDomainDataSource will automatically go to the server and fetch the new data according to the new SId. Your "Where" will be in the server method. Don't do any manual DomainContext stuff, since you will interfere with RadDomainDataSource. Don't touch the DomainContext that you give to RadDomainDataSource.

    To explore the new RadDomainDataSource control in greater depth, please check itsonline examples and take a look at the following blog posts:

    Please, cover the above resources since all of them contain sample projects that you will find very useful.

    I hope this helps.

    Greetings,
    Ross
    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
  3. DevCraft banner
Back to Top