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

ODataV4 custom adaptor headers ETag

Hi, my ODataV4 service expose ETag value in @odata.etag field, how can I set his value in request headers?

var customAdaptor = new ej.ODataV4Adaptor().extend({ 
            update: function (dm, keyField, value, tableName) { 
                return { 
                    type: "PATCH", 
                    url: dm.dataSource.url.replace(/\/*$/, tableName ? '/' + tableName : '') + '(\'' + value[keyField] + '\')', 
                    data: JSON.stringify(value), 
                    accept: this.options.accept,
                    headers: { "If-Match": VALUE_OF_ETAG }
                }; 
            } 
        })

Thanks

5 Replies

KV Karthikeyan Viswanathan Syncfusion Team January 26, 2017 04:14 PM UTC

Hi Emanuele Filardo  
  
Thanks for contacting Syncfusion support. 
 
 Please try the below code into your sample: 
<code> 
var customAdaptor = new ej.ODataV4Adaptor().extend({  
            update: function (dm, keyField, value, tableName) { 
                                      dm.dataSource.headers =[{ “If-Match”: VALUE_OF_ETAG }]; 
                return {  
                    type: "PATCH",  
                    url: dm.dataSource.url.replace(/\/*$/, tableName ? '/' + tableName : '') + '(\'' + value[keyField] + '\')',  
                    data: JSON.stringify(value),  
                    accept: this.options.accept 
                };  
            }  
        }) 
</code> 
  
 
 
Regards,  
Karthikeyan V.  
 



EF Emanuele Filardo January 26, 2017 04:27 PM UTC

Hi, I have problem to get VALUE_OF_ETAG, in the grid I've tried to add odata.etag but is recognized as an "expand" request, and in "value" object is not present.

This is the metadata: {"@odata.context":"https://localhost:44300/api/easycaregiverapi/$metadata#Assistiti","value":[{"@odata.etag":"W/\"YmluYXJ5J0FBQUFBQUFBQ09zPSc=\"","...


PO Prince Oliver Syncfusion Team January 27, 2017 11:52 AM UTC

Hi Emanuele,   
  
Thanks for your update.   
  
We were unable to replicate your scenario at our end. Please provide us an issue reproducible sample or code snippet along with replication steps, it will help us provide you a solution.   
  
If you are looking for accessing the header at server side, refer to the below code snippet.   
  
System.Web.HttpContext.Current.Request.Headers["If-Match"];   
 
Regards,   
Prince   



EF Emanuele Filardo January 28, 2017 01:59 PM UTC

I've found a solution, but I don't know if is the right way:
...
headers: { "If-Match": args.model.selectedRecords[0]["@@odata.etag"] }
...


PO Prince Oliver Syncfusion Team January 30, 2017 11:38 AM UTC

Hi Emanuele,     
    
Thanks for your update.     
    
Yes, you can set the value of “odata.etag” to “if-Match” in the header as per your shared code. Also, you can use the datasource headers “dm.dataSource.headers”  as mentioned in previous update to set value of “odata.etag”    
  
Regards,     
Prince     


Loader.
Live Chat Icon For mobile
Up arrow icon