My environment is razor frame, DataSourceRequest is how to process adding, deleting, modifying, and querying in batches

1 Answer 22 Views
Data Source Grid
ss
Top achievements
Rank 1
ss asked on 02 Dec 2023, 02:11 AM

Hello Teacher:

          My front-end code:

var dataSource = new kendo.data.DataSource({
                type: "aspnetmvc-ajax",
                pageSize: 25000,
                serverPaging: false,
                serverGrouping: false,
batch: true,
                transport: {
                    read: {
                        url: urlRead,
                        data: kendo.antiForgeryTokens(),
                        type:"GET"
                    },

                    create: {
                        url: urlCreate,
                        data: kendo.antiForgeryTokens(),
                        cache: true,

                    },
                    update: {
                        url: urlUpdate,
                        data: kendo.antiForgeryTokens(),
                        cache: true,
                    },
                    destroy: {
                        url: urlDestroy,
                        data: kendo.antiForgeryTokens(),
                        cache: true
                    },

                    parameterMap: function (data, type) {
                        //if (type == "create") {
                        //    // send the created data items as the "models" service parameter encoded in JSON
                        //    return { models: kendo.stringify(data.models) };
                        //}
                    }

                },
                //requestStart: function() {
                //    kendo.ui.progress($("#"+gridName), true);
                //},
                //requestEnd: function() {
                //    kendo.ui.progress($("#"+gridName), false);
                //},
                sync: function (e) {


                },
                schema: {
                    data: "Data",
                    total: "Total",
                    errors: "Errors",
                    model: model,
                    errors: function (response) {
                        //ShowNotification(response);
                        return response.error;
                    }
                },
                error: function (e) {
                    //ShowNotification("Error");
                    dataSource.cancelChanges();
                }
            });
            //dataSource.bind("error", function () { ShowNotification("dsError") });

            grid.setOptions({
                dataSource: dataSource,
                persistSelection: true,
                navigatable: true,
                resizable:true,
                reorderable:true,
                dataBound: function (e) {
                    if (e.sender.dataSource.view().length > 0) {
                        e.sender.select("tr:eq(0)");
                        grid.trigger("change");
                        grid.unbind("dataBound");
                    }

                }
            });

Processing data in batches, I don't know how the frontend sends backend requests and how the backend receives requests?

                                        

1 Answer, 1 is accepted

Sort by
0
Neli
Telerik team
answered on 06 Dec 2023, 06:44 PM

Hello,

As in your scenario you are using the 'aspnetmvc-ajax' type, you can take the endpoints used in Telerik UI for ASP.Net MVC/Telerik UI for ASP.Net Core demos as a reference for the Back-end code. For example, you can take a look at the endpoint of the Telerik UI for ASP.Net Core Grid Batch Editing Demo by clicking on the 'View Source' tab and then selecting EditingController.cs. For example, the Read and Cerate endpoint could be as below:

 

 public ActionResult Editing_Read([DataSourceRequest] DataSourceRequest request)
        {
            return Json(productService.Read().ToDataSourceResult(request));
        }

        [AcceptVerbs("Post")]
        public ActionResult Editing_Create([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")] IEnumerable<ProductViewModel> products)
        {
           ......
        }

 

Below you will find a screenshot that demonstrates the payload sent to the controller with batch editing:

I hope this helps. 

Regards,
Neli
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Kendo family, check out our getting started resources
Tags
Data Source Grid
Asked by
ss
Top achievements
Rank 1
Answers by
Neli
Telerik team
Share this question
or