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

Command items: command name RebindGrid

3 Answers 78 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Guilhem
Top achievements
Rank 1
Guilhem asked on 28 Mar 2017, 07:03 AM

Hello,

I noticed that both the command items "Cancel changes" and "Refresh" fire an event with the name "RebindGrid".
This is happening for both the client side (ClientEvents.OnCommand) and the server side (onItemCommand). And we can't add an argument for those native commands.

So we have a way to intercept those actions (the 2 events I mentionned above) but we can't know if the user has clicked on the "Cancel changes" button or the "Refresh" Button. That's too bad !
I note that we don't have this issue with the "Save changes" button and the "Add new record" button which have their own command names.

Is this something that could be changed in a future release ?

Thank you.

3 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 30 Mar 2017, 07:09 AM
Hello,

This is because basically they fire the same action, i.e. - blank event to refresh the grid. You can achieve this requirement using the following approach:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridCommandItem)
    {
        Button button = e.Item.FindControl("CancelChangesIcon") as Button;
        button.Attributes.Add("onmousedown", "cancelChangesClicked();");
    }
}
JavaScript:
var isCancelChanges = false;
function cancelChangesClicked() {
    isCancelChanges = true;
}
function gridCommand(sender, args) {
    if (args.get_commandName() == "RebindGrid" && isCancelChanges) {
        alert("Cancel Changes Initiated");
    }
}

I hope this will prove helpful.

Regards,
Eyup
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
Guilhem
Top achievements
Rank 1
answered on 30 Mar 2017, 07:53 AM

Hello Eyup,

Thank you for your answer.
I solved it with a very similar approach, and it's functionning. But I still think a (native) different command Name, or a (native) different argument would be better.

var isCancelChanges = false;
 
function GridCreated(sender, args) {
    $(sender.get_element()).find(".rgRefresh").each(function () {
        var clickhandler = this.onclick;
        this.onclick = null;
        $(this).click(function () {
            isCancelChanges = false;
        }).click(clickhandler);
    });
    $(sender.get_element()).find(".rgCancel").each(function () {
        var clickhandler = this.onclick;
        this.onclick = null;
        $(this).click(function () {
            isCancelChanges = true;
        }).click(clickhandler);
    });
}
 
function Command(sender, args) {
    switch (args.get_commandName()) {
        case "RebindGrid":
            if (isCancelChanges) {
                //Cancel
            }else{
                //Refresh
            }
            break;
        default: break;
    }
}
0
Eyup
Telerik team
answered on 03 Apr 2017, 03:26 PM
Hi Guilhem,

If you want this to be implemented built-in, you can log your idea in our feedback platform:
http://feedback.telerik.com/Project/108

Regards,
Eyup
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.
Tags
Grid
Asked by
Guilhem
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Guilhem
Top achievements
Rank 1
Share this question
or