How to call destroy method only?

14 posts, 0 answers
  1. Nick
    Nick avatar
    17 posts
    Member since:
    Jan 2015

    Posted 29 Mar 2017 Link to this post

    Hi 

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

    Please refer to pic1, my grid is inline batch update, I have one record in database, 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();
                }            
            }
        });
    }

     

  2. Stefan
    Admin
    Stefan avatar
    2834 posts

    Posted 30 Mar 2017 Link to this post

    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 visualization (charts) and form elements.
  3. Nick
    Nick avatar
    17 posts
    Member since:
    Jan 2015

    Posted 01 Apr 2017 in reply to Stefan Link to this post

    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. 

     

  4. Stefan
    Admin
    Stefan avatar
    2834 posts

    Posted 04 Apr 2017 Link to this post

    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.
  5. Nick
    Nick avatar
    17 posts
    Member since:
    Jan 2015

    Posted 07 Apr 2017 in reply to Stefan Link to this post

    Hi Stefan,

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

    Thanks. 

  6. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    2062 posts

    Posted 11 Apr 2017 Link to this post

    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.
  7. Nick
    Nick avatar
    17 posts
    Member since:
    Jan 2015

    Posted 12 Apr 2017 in reply to Boyan Dimitrov Link to this post

    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.

  8. Dimitar
    Admin
    Dimitar avatar
    463 posts

    Posted 14 Apr 2017 Link to this post

    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.
  9. Nick
    Nick avatar
    17 posts
    Member since:
    Jan 2015

    Posted 14 Apr 2017 in reply to Dimitar Link to this post

    Sorry I make a wrong operation. Please check this one.
  10. Stefan
    Admin
    Stefan avatar
    2834 posts

    Posted 18 Apr 2017 Link to this post

    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 visualization (charts) and form elements.
  11. Nick
    Nick avatar
    17 posts
    Member since:
    Jan 2015

    Posted 26 Apr 2017 in reply to Stefan Link to this post

    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.

  12. Stefan
    Admin
    Stefan avatar
    2834 posts

    Posted 28 Apr 2017 Link to this post

    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 visualization (charts) and form elements.
  13. Nick
    Nick avatar
    17 posts
    Member since:
    Jan 2015

    Posted 28 Apr 2017 in reply to Stefan Link to this post

    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.

  14. Stefan
    Admin
    Stefan avatar
    2834 posts

    Posted 02 May 2017 Link to this post

    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 visualization (charts) and form elements.
Back to Top