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

preventDefault() in beforeEdit inserts a new row on Create

2 Answers 2709 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dima
Top achievements
Rank 1
Dima asked on 20 Jun 2018, 03:21 PM

Hello,

we implemented an onBeforeEdit listener for our popup-editing-grid as follow:

this.beforeEditHandler = function (e) {
        var isDirty = dataSourceIsDirty();
        if (isDirty) {

            ...
            e.preventDefault();
        }
    }

When dirty grid-items exist, the edit-popup should not appear. This works fine when trying to edit a row, the popup is not being shown. However, when we try to create a new dataItem, the popup does not appear also, but a new empty row is being added to the grid (see attachment).

 

Any idea of how to prevent the grid to insert an empty row?

 

Thanks.

2 Answers, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 25 Jun 2018, 08:17 AM
Hello Dima,

This is because the empty row is created immediately when the users click the add button. In order to prevent creating that row I would suggest handling the click event for the add new record button and canceling the event if necessary. 

$(".k-grid-add").first().on("click", function(e) {
    e.preventDefault();
    e.stopPropagation();
});

I also prepared a dojo sample that outlines the approach:


Give it a try and let me know how it works for you.

Regards,
Viktor Tachev
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Dima
Top achievements
Rank 1
answered on 27 Jun 2018, 11:14 AM

Hello Viktor,

thank you, that approach works for us.

 

Regards,

Dima.

Tags
Grid
Asked by
Dima
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Dima
Top achievements
Rank 1
Share this question
or