We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Performs data Read operation on Custom DataAdaptor from code behind

Is there a way to push grid attached to custom DataAdaptor to do read operation from api.
My grid has custom adaptor implemented,CustomData adaptor is implemented as service, all of functions working great, 
Only thing that I can't figure is:
Is there a way to invoke Read operation with set DataManagerRequest
 public override object Read(DataManagerRequest dm, string key = null)

I did try to call Grid.Refresh(); from code behind, but this resets grid filters to initial state.
My grid has some filters set outside of scope columns in filter, these values we are passing in DataManagerRequest.Params (over query).
But idea is to let users also using default filters on grid.
I am trying to invoke reading method in CustomDataAdaptor with DataManagerRequest param which contain grid filtered,paged, sorted and other metadata.

5 Replies

LR Logesh Rajappa Syncfusion Team January 17, 2020 08:46 AM

Hi Admir, 
Thanks for contacting Syncfusion support 
We are quite unclear with the reported query, so we would like know the below details as it will help us resolve the issue asap. 
  1. By default, you can maintain the grid query property with the required operations. So why are params used outside query property?
  2. Share the full grid code?
  3. Share the exact scenario?
Please get back to us for further assistance. 
Logesh R 

AH Admir Hodžic January 17, 2020 09:42 AM

Thank you on trying to help,
First how, I can edit my text when pasting code to looks like code, When I write on forum my code beside is ugly it looks more ugly without formating.

3. Share the exact scenario?
My grid using CustomDataAdapter, in custom data adapter I do override Read method

public override object Read(DataManagerRequest dm, string key = null)
string docTip = (string)dm.Params.Where(x => x.Key == "docTip").Select(x => x.Value).FirstOrDefault();
            IEnumerable <Models.Robno.Dokumenti> DataSource = Dokumenti(userId, odDatuma, doDatuma, sklBroj,docTip);
            if (dm.Search != null && dm.Search.Count > 0)
                // Searching
                DataSource = DataOperations.PerformSearching(DataSource, dm.Search);
            if (dm.Sorted != null && dm.Sorted.Count > 0)
                // Sorting
                DataSource = DataOperations.PerformSorting(DataSource, dm.Sorted);
            if (dm.Where != null && dm.Where.Count > 0)
                // Filtering
                DataSource = DataOperations.PerformFiltering(DataSource, dm.Where, dm.Where[0].Operator);

            int count = 0;
            if (dm.RequiresCounts)
                count = DataSource.Cast<Models.Robno.Dokumenti>().Count();

            if (dm.Skip != 0)
                DataSource = DataOperations.PerformSkip(DataSource, dm.Skip);
            if (dm.Take != 0)
                DataSource = DataOperations.PerformTake(DataSource, dm.Take);

            return dm.RequiresCounts ? new DataResult() { Result = DataSource, Count = count } : (object)DataSource;

In this method I am using extra extra parameters provided by adding param to query
string docTip = dm.Params.Where(x => x.Key == "docTip").Select(x => x.Value).FirstOrDefault();

Parameter docTip user setting on form in control which is not part of grid.

On blazor page razor component adding docTip   param I do like so:

Grid using  Query="@dodataniParametri"  definde 

Gird has event handler on 

<GridEvents  OnActionBegin="ActionBeginHandler" TValue="Models.Robno.Dokumenti">

Handle adding params to query

 dodataniParametri.AddParams("docTip", docTip);

All this working very nice,

My problem is:

When on blazor form param docTip change value.
How to push grid to perform read operation and call read method in CustomDataAdapter service with DataManagerRequest  .

To be clear , I know how when docTip is changed, 

What I did to try is to call Grid.Refresh()  this triggers grid to call Read method on CustomDataAdapter  with DataManagerRequest  ,
But this also delete (restart) users filter and ordering set on columns in grid.

I am going to try write sample as soon as possible to publish here.

VN Vignesh Natarajan Syncfusion Team January 20, 2020 09:08 AM

Hi Admir, 
Thanks for the update.  
Query: “How to push grid to perform read operation and call read method in CustomDataAdapter service with DataManagerRequest  . 
From your query we understand that you want to refresh the grid upon changing the additional parameters value.  We suggest you to achieve your requirement by changing the entire Query property instead of that particular property in the Query.  
(i.e) in your code example, We suggest you to change the Query="@dodataniParametri" instead of changing the docTip upon changing the additional parameters value. For your convenience we have prepared a sample to modify the query to increase the number of records in grid. Refer the below code example and sample for your reference 
<EjsButton OnClick="Change">Increase Data</EjsButton> 
<EjsGrid TValue="Order" ID="Grid" AllowSorting="true" Query=@GridQuery AllowFiltering="true" AllowPaging="true"> 
    <EjsDataManager AdaptorInstance="@typeof(CustomAdaptor)" Adaptor="Adaptors.CustomAdaptor"></EjsDataManager> 
    <GridPageSettings PageSize="8"></GridPageSettings> 
. . . . . .. . . . .  
    public int ParamValue = 2; 
    public void Change() 
        ParamValue = ParamValue + 2; 
        GridQuery = new Query().AddParams("ej2grid", ParamValue); 
    public static List<Order> Orders { get; set; } 
    public Query GridQuery { get; set; } 
    protected override void OnInitialized() 
        GridQuery = new Query().AddParams("ej2grid", ParamValue); 
        . . . . . . . . . .. . . .  
Refer our UG documentation for your reference 
Please get back to us if you have further queries.  
Vignesh Natarajan. 

AH Admir Hodžic January 29, 2020 05:41 AM

My apologies for late response, 
Thank you on your solution.
Setting new query does perform new request read to dataadapter 

VN Vignesh Natarajan Syncfusion Team January 29, 2020 10:49 PM

Hi Admir,  
Thanks for the update.  
We are glad to hear that you are able to resolve your query using our solution. 
Kindly get back to us if you have further queries.  
Vignesh Natarajan. 

Live Chat Icon For mobile
Up arrow icon