When using the ODataV4Adaptor how do I use PUT in the datamanager instead of PATCH to update

Good day

I am creating a grid using odata for searching and filtering but I have realized that it uses PATCH for updating. How do I use PUT instead?

    <ejs-grid id="Grid" toolbar="@(new List<string>() { "Add", "Edit", "Update", "Cancel" })" allowPaging="true" allowSorting="true" allowFiltering="true" actionFailure="actionFailure">
        <e-data-manager url="https://localhost:6001/odata/TableCollections" adaptor="ODataV4Adaptor" crossdomain="true" updateUrl="https://localhost:6001/api/v1/TableCollections" ></e-data-manager>
        <e-grid-editSettings allowAdding="true" allowDeleting="true" allowEditing="true" mode="Dialog"></e-grid-editSettings>
        <e-grid-pagesettings pageSize="7">
        </e-grid-pagesettings>
        <e-grid-columns>
            <e-grid-column field="ID" headerText="ID" visible="false" isPrimaryKey="true" textAlign="Right" width="120"></e-grid-column>
            <e-grid-column field="Code" headerText="Code" width="150"></e-grid-column>
            <e-grid-column field="ShortDescription" headerText="Short Description" width="150"></e-grid-column>
            <e-grid-column field="LongDescription" headerText="Long Description" width="170"></e-grid-column>
        </e-grid-columns>
    </ejs-grid>

Thank you

5 Replies 1 reply marked as answer

SK Sujith Kumar Rajkumar Syncfusion Team September 14, 2020 12:14 PM UTC

Hi Ronald, 
 
Greetings from Syncfusion support. 
 
We checked your query and would like to let you know that the default(pre-defined) HTTP methods will only be called for ODataV4 requests for the Grid actions. The Get request will be sent for getting initial data and while Grid actions like, searching, filtering, etc. are performed and Post, Patch and Delete requests will be sent for add, update and delete CRUD operations respectively. These are the default ODataV4 methods called for each operation and it cannot be modified. 
 
You can however specify custom URL’s for OdataV4 CRUD actions using the insertUrl, updateUrl and removeUrl in the data manager definition bound to the Grid. 
 
Let us know if you have any concerns. 
 
Regards, 
Sujith R 



RW Ronald Walcott September 16, 2020 03:41 PM UTC

Sorry. Are you saying that using the updateUrl will call the PUT verb?

Do you have any examples showing this? I have instead created a custom adaptor based on OData, injected the base URL into the view and changed the update to use PUT. Is this the wrong way to do it?

 <ejs-grid id="Grid" toolbar="@(new List<string>() { "Add", "Edit", "Update", "Cancel" })" allowPaging="true" allowSorting="true" allowFiltering="true" actionFailure="actionFailure" created="created" actionComplete="complete">
        <e-grid-editSettings allowAdding="true" allowDeleting="true" allowEditing="true" mode="Dialog"></e-grid-editSettings>
        <e-grid-pagesettings pageSize="7">
        </e-grid-pagesettings>
        <e-grid-columns>
            <e-grid-column field="ID" headerText="ID" visible="false" isPrimaryKey="true" textAlign="Right" width="120"></e-grid-column>
            <e-grid-column field="Code" headerText="Code" width="150"></e-grid-column>
            <e-grid-column field="ShortDescription" headerText="Short Description" width="150"></e-grid-column>
            <e-grid-column field="LongDescription" headerText="Long Description" width="170"></e-grid-column>
        </e-grid-columns>
    </ejs-grid>


<script>
    function created(args) {
        var grid = document.querySelector('#Grid').ej2_instances[0];
        grid.dataSource = new ej.data.DataManager({
            url: "@Configuration["ApiResourceBaseUrls:Api"]/odata/TableCollections",
            adaptor: new ej.data.ODataV4Adaptor({ updateType: 'PUT' })
        });
    }
</script>


BS Balaji Sekar Syncfusion Team September 18, 2020 05:08 PM UTC

Hi Ronald, 
 
Sorry for inconvenience caused, 
 
Query #1: Are you saying that using the updateUrl will call the PUT verb? 
 
In your first update we misunderstood your query so only we suggested the custom adaptor with updateUrl option. 
 
Based on your query, we suspect that you want use “PUT” verb instead of “PATCH” while update a record. Since we suggest you to set the PUT value into UpdateType property of ODataV4Adaptor. It will override the default HTTP request type of “PATCH” to “PUT”. 
 
Query #2:  I have instead created a custom adaptor based on OData, injected the base URL into the view and changed the update to use PUT. 
 
By default, ODataV4Adaptor send the “PATCH” request to server while updating a record. To achieve the ODataV4Adaptor need to send the “PUT” request instead of “PATCH” using updateType property of ODataV4Adaptor. 
 
We have set updateType as "PUT" in the ODataV4Adaptor which is defined in Grid's load event. 
 
If you need to customize the default HTTP Request action in the ODataV4Adaptor, we can use the custom Adaptor from ODataV4Adaptor. 
 
For your reference, we have shared a custom adaptors Documentation as given below 
 
 
Query #3: Do you have any examples showing this? 
 
Based on your query, We have created a sample with ODataV4Adaptor in the ASP .Net Core platform. 
 
Please refer the below code example and sample for more information.  
 
[index.cshtml] 
    <ejs-grid id="Grid" allowPaging="true" allowsorting="true" allowFiltering="true" toolbar="@(new List<string>() {"Add","Edit","Delete","Update","Cancel" })" load="load"> 
        <e-grid-editSettings allowAdding="true" allowEditing="true" allowDeleting="true"></e-grid-editSettings> 
         
        <e-grid-columns> 
            <e-grid-column field="Id" headerText="Product ID" isPrimaryKey="true" textAlign="Right" width="160"></e-grid-column> 
            <e-grid-column field="Author" headerText="Author" width="170"></e-grid-column> 
            <e-grid-column field="Title" headerText="Title" textAlign="Right" width="170"></e-grid-column> 
        </e-grid-columns> 
    </ejs-grid> 
 
 
    <script> 
        function load() { 
            this.dataSource = new ej.data.DataManager({ url: "/odata/Books", adaptor: new ej.data.ODataV4Adaptor({ updateType: 'PUT' }) });      
        } 
    </script> 
 
[Bookscontroller.cs] 
[Route("api/[controller]")] 
    public class BooksController : ODataController 
    { 
        . . . . . 
       // GET api/values 
        [HttpGet] 
        [EnableQuery] 
        public IQueryable<Book> Get() 
        { 
            return _db.Books; 
        } 
 
        // POST api/values 
        [HttpPost] 
        [EnableQuery] 
        public IActionResult Post([FromBody]Book book) 
        { 
            _db.Books.Add(book); 
            _db.SaveChanges(); 
            return Created(book); 
        } 
 
        // PUT api/values/5 
        [HttpPut("{id}")] 
        public async Task<Book> Put(int id, [FromBody] Book book) 
        { 
            var entity = await _db.Books.FindAsync(book.Id); 
            _db.Entry(entity).CurrentValues.SetValues(book); 
            await _db.SaveChangesAsync(); 
            return book; 
        } 
 
        // DELETE api/values/5 
        [HttpDelete("{id}")] 
        public async Task<int> Delete(int key) 
        { 
            var od = await _db.Books.FindAsync(key); 
 
            _db.Books.Remove(od); 
            await _db.SaveChangesAsync(); 
            return key; 
        } 
    } 
 
 
For your reference, we have shared the NetWork tab screenshot for HTTP Request with Grid actions  
 
Initial Rendering: 
 
Filtering:  
 
 
Update with “PUT” request 
 
 
Please get back to us if you need further assistance. 
 
Regards, 
Balaji Sekar 


Marked as answer

RW Ronald Walcott September 18, 2020 05:24 PM UTC

Thanks, that answered my question.


BS Balaji Sekar Syncfusion Team September 21, 2020 12:11 PM UTC

Hi Ronald, 

Thanks for you update. 

We are happy to hear that the provided solution was helpful to achieve your requirement. 

Please get back to us if you need further assistance from us. 

Regards,
Balaji Sekar 


Loader.
Up arrow icon