This is a migrated thread and some comments may be shown as answers.
create function not being picked up
1 Answer 2 Views
This is a migrated thread and some comments may be shown as answers.
Darren
Top achievements
Rank 1
Darren asked on 01 Dec 2020, 12:22 PM

so I recently created a grid called Regionmappinggrid, which has a datasource of RegionalMappingDataSource. What I'm trying to do is call the create function in the datasource from the toolbar element name create, but having no luck so far could some please help me out ? All of the code is below

      var RegionalMappingDataSource = new kendo.data.DataSource({
            transport: {
                read: function(options) {
                    $.ajax({
                        url: siteRoot + '/Admin/RegionMapping/GetRegionMappings',
                        type: 'GET',
                        success: function(result) {

                            console.log(result);
                            options.success(result);
                        },
                        error: function(result) {
                            options.error(result);
                        }
                    });
                },
                create: function() {
                    console.log("hrllo00");


                },

                update: function () {
                    console.log("hello!");
                },

                parameterMap: function(options, operation) {
                    if (operation !== "read" && options.models) {
                        return { models: kendo.stringify(options.models) };
                    }
                },
                //schema: {
                //    model: {
                //        CountryName: { field: "CountryCode", type: "string" },
                //        CountryID:{"CountryId", type: "string" }
                //    RegionId: "RegionID",
                //    RegionOtherName: "Name",
                //    UpdatedDate: "UpdatedDate"
                //}

                //}
                schema: {
                    model: {
                        id: "RegionMappingId"
                        //fields: {
                        //    CountryId: { type: "number", editable: false},
                        //    CountryCode: { type: "string", editable: true },
                        //    RegionName: { type: "string", editable: true },
                        //    RegionId: { type: "number", editable: true},
                        //    Name: { type: "string", editable: true},
                        //    UpdatedDate: { type: "date" }

                        //}

                    }
                }
            }


        });

 

 $("#Regionmappinggrid").kendoGrid({
            sortable: true,
            pageable: {
                refresh: true,
                pageSizes: true,
                buttonCount: 5
            },
            editable: "inline",
            toolbar: [{ name: "create", text: "Update Other Region Name" }],
            columns: [
                {
                    title: "Country Name",
                    field: "CountryCode",
                    editor: function(container, options) {
                        var input = $('<input required id="mapping" name="' + options.field + '"/>');
                        input.appendTo(container);
                        input.kendoDropDownList({
                            autoBind: true,
                            optionLabel: 'Please Select Country....',
                            dataTextField: "Value",
                            dataValueField: "Key",
                            dataSource: getCountryName,
                            value: options.model.Key,
                            text: options.model.Value
                        }).appendTo(container);
                    }

                },
                {
                    title: "Region Name",
                    field: "RegionName",
                    editor: function(container, options) {
                        var input = $('<input required id="mapping1" name="' + options.field + '"/>');
                        input.appendTo(container);
                        input.kendoDropDownList({
                            autoBind: false,
                            optionLabel: 'Please Select Region....',
                            dataTextField: "Value",
                            dataValueField: "Key",
                            dataSource: getRegionName,
                            value: options.model.Key,
                            text: options.model.Value
                        }).appendTo(container);
                    }

                },
                {
                    title: "Region ID",
                    field: "RegionId",
                    hidden: false
                },
                {
                    title: "Other Name",
                    field: "Name"
                },
                {
                    title: "Updated On",
                    field: "UpdatedDate",
                    format: "{0: yyyy-MM-dd HH:mm:ss}",
                    editable: function() { return false; }
                },
                {
                    command: ["edit", "destroy"]
                }
            ],
            dataSource: RegionalMappingDataSource

1 Answer, 1 is accepted

Sort by
0
Tsvetomir
Telerik team
answered on 03 Dec 2020, 06:49 AM

Hi Darren,

The Create function of the DataSource is called when the user presses the "Update" button that is rendered on the row of the new item. Can you confirm that upon pressing the "Update" button, the function is executed as expected?

As per automatically calling the Create function after the "Add new item" button is clicked, you should set the AutoSync property of the DataSource to "true". This would cause it to update automatically right after every change.

https://docs.telerik.com/kendo-ui/api/javascript/data/datasource/configuration/autosync

 

Kind regards,
Tsvetomir
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Grid
Asked by
Darren
Top achievements
Rank 1
Answers by
Tsvetomir
Telerik team
Share this question
or