0
votes
 transport: {
            parameterMap: function (data, operation) {
                if (operation !== "read") {
                    return JSON.stringify(data);
                } else {
                    return (data);
                }
            },
            read: {
                url: function () {
                    return moduleServiceRoot;
                },
                type: "GET",
                dataType: "json",
                async: true
            },
            create: {
                url: function (rec) {
                    return moduleServiceRoot; 
                },
                type: "POST",
                contentType: 'application/json; charset=utf-8',
                dataType: "json",
                async: true
            },
            complete: function (e) {
                $("#grid").data("kendoGrid").dataSource.read();
                async: true
            },
        },
        requestStart: function (e) {
            console.log('request started');
            if (e.type == 'create' & validInput == false) {
                console.log('request started');
                e.preventDefault();
            }
        }

in the above code validInput is always false. if i comment out the if statement kendo grid read operation is prevented (grid does not show any data) but if i uncomment it, it won't work for kendo create, when i hit update in kendo popup editor.

1
I'm not sure if e.preventDefault is the right way to abort an XML HTTP request. Have you tried using the abort method?Thilak Rao
You are right, KendoUI checks for read type the return value but not for other events. But agree with @ThilakRao, under which circumstances do you want to cancel the update? Maybe it is easier somewhere else and with less side effectsOnaBai
@OnaBai I want to cancel the create event if a user tries to add a existing record.I am actually validating user input with values in Database & displaying kendoAlert,Everything is working but not able to cancel create event as a result duplicate values are getting added in DB.@Thilak Rao no i have not tried that.Arun

1 Answers

1
votes
create: function (options) {
                if (validInput) {
                    $.ajax({
                        url: moduleServiceRoot,
                        dataType: "json",
                        type: "POST",
                        contentType: 'application/json; charset=utf-8',
                        async: true,
                        data: JSON.stringify(options.data),
                        success: function (result) {            // notify the data source that the request succeeded,
                            options.success(result);
                        },
                        error: function (result) {              // notify the data source that the request failed
                            options.error(result);
                        }
                    });
                }
            }

and it works fine