SfGrid - DataManager - UrlAdaptor different request and response structures

Hi,


I would like to use extended models in urlapadaptor.

It would be different structure in request and different in response than the data type of grid.

For example an edit action response:

{

"Data" : {<it is instance of the grid type>},

"Message" : "Custom message to show in page if not empty"

}

Show the "Message" and throw the Data object to the grid in one request-response process.


Is there any way to manipulate request and response objects in urladaptor?

Any event or something...


I tried to inherit the urladaptor and use it as customadaptor, but it causes type error in runtime. If I tried to use as urladaptor, than the original adaptor works, I think.

I tried to create custom adaptor from DataAdaptor, but it used a websocket. I want to use simple rest api requests.


I would like similar working as urladaptor, but custom requests and response handling.


Thanks for your help!


Best regards,

Otto


3 Replies

RN Rahul Narayanasamy Syncfusion Team February 11, 2022 01:33 PM UTC

Hi Otto, 

Greetings from Syncfusion. 

We suspect that you want to customize the data request and the data response. If yes, then we have option to override internal methods of UrlAdaptor class. So we suggest you to check your scenario by overriding the ProcessQuery and  ProcessResponse method of UrlAdaptor class. Inside this ProcessQuery and  ProcessResponse method you can perform your custom customization. Please refer and use as like the code below 

 
<SfGrid @ref="Grid" ID="GridOneTwo" TValue="EmployeeData" AllowPaging="true" AllowFiltering="true"> 
    <SfDataManager @ref="DataManagerRef" Url="/api/Values" Adaptor="Adaptors.UrlAdaptor"></SfDataManager> 
    <GridColumns> 
        <GridColumn Field=@nameof(EmployeeData.Id) HeaderText="Id" IsPrimaryKey="true" IsIdentity="true" Visible="true" ShowInColumnChooser="false" /> 
        . ..  
    </GridColumns> 
</SfGrid> 
 
@code{ 
    SfGrid<EmployeeData> Grid; 
    public SfDataManager DataManagerRef { get; set; } 
 
    protected override void OnAfterRender(bool firstRender) 
    { 
        if (firstRender) 
        { 
            DataManagerRef.DataAdaptor = new TestOData(DataManagerRef); 
        } 
        base.OnAfterRender(firstRender); 
    } 
 
    public class TestOData : UrlAdaptor 
    { 
        public TestOData(DataManager dm) : base(dm) 
        { 
        } 
        public override object ProcessQuery(DataManagerRequest queries) 
        { 
            RequestOptions ActualReturnValue = (RequestOptions)(base.ProcessQuery(queries)); 
            //you can customize the query here 
            Console.WriteLine(ActualReturnValue.Url); 
            Console.WriteLine(ActualReturnValue.BaseUrl); 
            return ActualReturnValue; 
        } 
        public override async Task<object> ProcessResponse<T>(object data, DataManagerRequest queries) 
        { 
            HttpResponseMessage response = data as HttpResponseMessage; 
 
            //you can customize the response here 
 
            var ActualReturnValue = await base.ProcessResponse<T>(data, queries); 
            return ActualReturnValue; 
        } 
    } 
} 


Please let us know if you have any concerns. 

Regards, 
Rahul 
 



ON Otto Nagy February 16, 2022 07:57 PM UTC

Thanks for your help. I am looking for this solution.



RN Rahul Narayanasamy Syncfusion Team February 17, 2022 11:17 AM UTC

Hi Otto, 

Thanks for the update. 

We are happy to hear that the provided solution was helpful. Please get back to us if you need further assistance. 

Regards, 
Rahul 


Loader.
Up arrow icon