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

Prevent submit on return and fire an Update command

3 Answers 360 Views
Grid
This is a migrated thread and some comments may be shown as answers.
hjd
Top achievements
Rank 1
hjd asked on 22 Sep 2015, 03:17 PM

I have a RadGrid, on which I enabled the Edit mode. When I hit the edit icon a column from the grid can be edited (see the attached Grid2.png). At this point I want to edit the text and confirm with ENTER. On hitting ENTER I want to prevent the form submission and fire the grid update command. Unfortunately the submission prevention doesn't work, the grid update command is fired. Here is what I tried:

 function OnGridKeyPressed(sender, eventArgs) {
    if (eventArgs.get_keyCode() === 13) {
        Cancel​Submission(eventArgs);
        var mtv = $find(sender.ClientID).get_masterTableView();
        var items = mtv.get_editItems();
        if (items.length == 1) {
            var idx = items[0].get_itemIndexHierarchical();
            mtv.fireCommand('Update', idx);
        }
    }
}

function CancelSubmission(args) {
    args.set_cancel(true);
    return false;
}

Also this in Cancel​Submission: 

function Cancel​Submission() {
    var e = window.event;
    e.cancelBubble = true;
    e.returnValue = false;
    if (e.stopPropagation) {
        e.stopPropagation();
        e.preventDefault();
}

Any help will be appreciated!

 

Thanks in advance

Vasil

3 Answers, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 25 Sep 2015, 09:36 AM
Hello,

Note that the commands like Edit, Update, Cancel etc grid commands make an implicit call to the Rebind() method of RadGrid in order to refresh the control's content and fetch the latest information from the grid source. Take a look at this article to more about Commands that invoke Rebind() implicitly.
You may try to disable the ViewState. As mentioned in the documentation, when RadGrid's ViewState is turned off, the NeedDataSource event does not fire after any of the commands.

Regards,
Maria Ilieva
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
hjd
Top achievements
Rank 1
answered on 07 Oct 2015, 03:16 PM

Hello Maria,

First of all, thank you for your reply and sorry for taking me so long to answer. I think you didn't understand me correct. My problem is not the execution of the Rebind() method, but the form submission on hitting RETURN. The problem ocurs mainly in Mozilla Firefox, because in my method Cancel​Submission() window.event resp. e is undefined and I cannot cancel the form submission.

Anyway, I managed to resolve my problem. After digging a while I saw the method get_domEvent() in your eventArgs object. Passing this domEvent to the CancelSubmission() method did the trick. Here is my working code:

 

function OnGridKeyPressed(sender, eventArgs) {
    if (eventArgs.get_keyCode() === 13) {
        Cancel​Submission(eventArgs.get_domEvent());
        var mtv = $find(sender.ClientID).get_masterTableView();
        var items = mtv.get_editItems();
        if (items.length == 1) {
            var idx = items[0].get_itemIndexHierarchical();
            mtv.fireCommand('Update', idx);
        }
    }
}

 

function Cancel​Submission(domEvent) {
    // prevent misbehaviour in Firefox
var e = null;     
if (window.event) {         
e = window.event;     
}
else {
e = domEvent;
}
e.cancelBubble = true;
e.returnValue = false;
if (e.stopPropagation) {
e.stopPropagation();
e.preventDefault();
}
}

0
Maria Ilieva
Telerik team
answered on 12 Oct 2015, 10:16 AM
Hi,

I'm glad that you were able to fix the issue on your end. Do not hesitate to contact us back in case further assistance is needed.

Regards,
Maria Ilieva
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
hjd
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
hjd
Top achievements
Rank 1
Share this question
or