ASP.NET CORE MVC Don't want to reload Flexgrid when using BatchEditing

Posted by: thanhthuyeths on 17 January 2024, 11:05 am EST

  • Posted 17 January 2024, 11:05 am EST

    Hello,

    I am using BatchEdit, after calling BatchEdit, the flexgrid will be reloaded, but I don’t want to reload the flexgrid because I am loading the flexgrid using ajax. I see the function below is forcing data to be returned to flexgrid. Is there any way to not reload?

    please help me!

    public ActionResult GridBatchEdit([C1JsonRequest]CollectionViewBatchEditRequest<Customer> requestData)
    {
        return this.C1Json(CollectionViewHelper.BatchEdit<Customer>(requestData, batchData =>
        {
    	................
    	return new CollectionViewResponse<Customer>
            {
                Error = error,
                Success = success,
                OperatedItemResults = itemresults
            };
        }, () => db.Customers.ToList<Customer>())); 
    }

  • Posted 17 January 2024, 8:57 pm EST

    Hi,

    For this, You may need to create your endpoint at the server for handling the batch edit request. Please refer to the following code snippet and attached sample that explains the same.

    document.querySelector("#updateBtn").addEventListener("click", () => {
                let cv = grid.collectionView;
                let bodyPayload = {
                    ItemsCreated: cv.itemsAdded.slice(),
                    ItemsUpdated: cv.itemsEdited.slice(),
                    ItemsDeleted: cv.itemsRemoved.slice(),
                }
    
                fetch("/Home/BatchEdit", {
                    headers: {
                        'Accept': 'application/json',
                        'Content-Type': 'application/json'
                    },
                    method: "post", body: JSON.stringify(bodyPayload)
                })
    
            });
    
    //Server
    
            public IActionResult BatchEdit([FromBody] BatchInfo<Product> requestData)
            {
                try
                {
                    //Update the data here to DB
                    requestData.ItemsCreated.ForEach((item) =>
                    {
                        //add the items created In The DB
                    });
    
    
                    requestData.ItemsUpdated.ForEach((item) =>
                    {
                        //Update the items In The DB
                    });
    
                    requestData.ItemsCreated.ForEach((item) =>
                    {
                        //Delete the items In The DB
                    });
                }
                catch (Exception e)
                {
    
                    //YOu can thro error from here if anything goes wrong
                    throw e;
    
                }
                
    
    
                return Ok("Updated");
            }
    

    Regards.

    Avinash

    Batch_Edit_Ajax.zip

  • Posted 18 January 2024, 3:15 pm EST

    I understand.

    Thank you for your help.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels