This is a migrated thread and some comments may be shown as answers.

How to call destroy method only?

13 Answers 1352 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Nick
Top achievements
Rank 1
Nick asked on 29 Mar 2017, 11:07 AM

Hi 

I get some problem when I try to delete a record in Grid. They method will call the create and update method which is I don't want.

Please refer to pic1, my grid is batch update, I have one record in , then click Add new record button to add two new records but not save into database yet. At this moment, there are three records in grid, then I click the delete button on the third row, it will trigger the create method to transfer the two new records to the backend, this is I don't want, because I have not typed any value, it will get error in my backend.

So my question is there any way to ignore the create, update method when I click the delete button?

Below is the method of my custom Delete button.

function onDeleteConfirm_VendorSalesRepsGrid(e, obj) {
    e.preventDefault();
    var dataItem = obj.dataItem($(e.target).closest("tr"));
    CustomConfirmDialog("Are you sure you want to delete this Vendor Sales Reps?", function test2(result) {
        if (result === true) {
            var dataSource = $("#VendorSalesRepsGrid").data("kendoGrid").dataSource;
            dataSource.remove(dataItem);
            //If the id equal to 0, it means that this record does not existed in database. so no need to run the sync().
            if (dataItem.id != 0) {
                dataSource.sync();
            }            
        }
    });
}

 

13 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 30 Mar 2017, 09:09 AM
Hello Nick,

When batch editing is used the Grid will send all changes to the server(Create, Update, Delete) by default, and the Grid does not support out of the box making only some of the requests.

Also, the requests will be made once the user saves the changes, not when the destroy button is clicked. Please observe our example demonstrating the expected behaviour:

http://demos.telerik.com/kendo-ui/grid/editing

Also, if the new items, does not have to be sent as they will not pass the validation on the server, I can suggest setting a validation on the client as well, to ensure that empty items will not be sent to the server.

Regards,
Stefan
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data (charts) and form elements.
0
Nick
Top achievements
Rank 1
answered on 01 Apr 2017, 12:14 PM

Hi Stefan,

Thanks to confirms it. But I think it is had to setting a validation on the client, refer to Pic2.png I have added the validation method on the Save Change function, but it does not work and send the new create or update data to back-end when running the sync. 

 

0
Stefan
Telerik team
answered on 04 Apr 2017, 10:56 AM
Hello Nick,

I was not able to reproduce the same issue on my end.

I used a similar logic of the saveChanges event, and the Grid does not send any requests to the server if the function is returning true:

http://dojo.telerik.com/Ejeros

I can assume that there is a custom factor which we are overlooking at this moment. Please modify the provided example or send a new one reproducing the issue and I will gladly assist.

Regards,
Stefan
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Nick
Top achievements
Rank 1
answered on 07 Apr 2017, 07:53 AM

Hi Stefan,

Please refer to Pic3.png, I have added my code in the demo, please check it.

Thanks. 

0
Boyan Dimitrov
Telerik team
answered on 11 Apr 2017, 06:22 AM

Hello Nick,

Please refer to the updated version of the sample http://dojo.telerik.com/Ejeros/3. As soon as the customFunction returns true there are no requests sent to the server (both update and delete). 

Regards,
Boyan Dimitrov
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Nick
Top achievements
Rank 1
answered on 12 Apr 2017, 12:00 PM

Hi Boyan,

Thanks for checking my issue. Maybe I am not describing clear enough. Since I don't know how to create this demo in the todo.telerik.com. So I create it from VS2015. This program can repeat my issue. Please check it.

0
Dimitar
Telerik team
answered on 14 Apr 2017, 10:56 AM
Hi Nick,

I am afraid that the attached zip contains only a solution file and .vs folder with settings. There are no files with your actual implementation. Please reattach the proper zip to your reply.

As far as the Kendo UI  Dojo is concerned, in order to create a Dojo sample , you should paste your code on the left pane (keep the CDN references in the head) and click the Run button. When your scenario is visualized on the right pane, there will be a unique random URL generated for it in the address bar. Copy it and paste it in your reply. Note that sometimes the URL could be updated with version ending (e.g. yourURL/2) after you change your code and run it. You need to send the proper URL, which could be used for issue reproduction.

Regards,
Dimitar
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Nick
Top achievements
Rank 1
answered on 14 Apr 2017, 11:11 AM
Sorry I make a wrong operation. Please check this one.
0
Stefan
Telerik team
answered on 18 Apr 2017, 07:52 AM
Hello Nick,

The provided files are not in a runnable project, still, I used the logic to create a runnable example, but the issue is still not reproducible.

I can assume that there is an important detail(step) that we are missing here.

Could you please send a screencast demonstrating the issue, so I can replicate it locally and try to provide a suggestion best suited for it.

Thank you in advance.

Regards,
Stefan
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data (charts) and form elements.
0
Nick
Top achievements
Rank 1
answered on 26 Apr 2017, 08:50 AM

Hi Stefan,

Sorry I cannot send you the screencast here. the file is too large to upload. 

I just can make some screenshots in excel to show you how to open the website project and repeat the issue. Please check it. Thanks.

0
Stefan
Telerik team
answered on 28 Apr 2017, 06:08 AM
Hello Nick,

Thank you for the detailed information.

After testing it, I noticed that the following function which is called on delete is manually calling the sync method which will send the request. This occurs because the sync is not called with the saveChanges button and the event is not prevented:

if (dataItem.id != "" && dataItem.id != null) {
    dataSource.sync();
}

Regards,
Stefan
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data (charts) and form elements.
0
Nick
Top achievements
Rank 1
answered on 28 Apr 2017, 06:46 AM

Hi Stefan,

Thank you for your confirm.

And the reason why I am calling the sync, it is because when I use the "destroy" command, it does not trigger the delete event to backend, it just delete record in grid's datasource. So I just can create an custom delete method.

As I mention on the top, is there any existed way to ignore the create, update method when call sync()? If not existed, I think I just can use ajax to call the DestroyData() on backend directly.

0
Stefan
Telerik team
answered on 02 May 2017, 07:48 AM
Hello Nick,

Currently, if the sync methods are called this will make the requests to the server, but the requests are not preventable.

I can suggest the other approach to use Ajax to call DestroyData() on backend directly.

Regards,
Stefan
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data (charts) and form elements.
Tags
Grid
Asked by
Nick
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Nick
Top achievements
Rank 1
Boyan Dimitrov
Telerik team
Dimitar
Telerik team
Share this question
or