How to disable a grid button after successful post

1 Answer 332 Views
Grid
Scott
Top achievements
Rank 1
Scott asked on 10 Jun 2022, 08:24 PM

I have an ajax post method where the user will sign up for an open slot. After the slot gets assigned, I want to disable the button and change the text. Can anyone tell me what I'm doing wrong here. I'm coming from Web Forms to MVC so it's been a little learning curve.

 

here's my grid

@(Html.Kendo().Grid(Model)
                .Name("Grid")
                .Columns(columns =>
                {
                    columns.Bound(p => p.Id).Hidden(true);
                    columns.Bound(p => p.JobStartDateTime).Visible(false);
                    columns.Bound(p => p.JobInfo).Title("Job");
                    columns.Bound(p => p.JobTimes).Title("Times");
                    columns.Bound(p => p.JobPayDisplay).Title("Pay");
                    columns.Command(cmd => cmd.Custom("Details").Click("Details"));
                    columns.Command(cmd => cmd.Custom("Sign Up").Click("SignUp"));


                })
                .Pageable()
                .Scrollable(scr => scr.Height(500))
                        .DataSource(dataSource => dataSource
                            .Ajax()
                            .PageSize(20)
                            .ServerOperation(false)
                        )
                )

and then here's the javascript function

 


function SignUp(e) {
        var id = $(e.currentTarget).closest("tr").find('td:first').html();
        $.ajax({
            type: 'POST',
            url: '/Jobs/SignUp',
            data: {id : id},
            headers: { "RequestVerificationToken": $('input[name="__RequestVerificationToken"]').val() },
            contentType: 'application/x-www-form-urlencoded; charset=UTF-8', 
            success: function (result) {
                alert(result);
                $(this).find(".k-grid-SignUp").addClass("k-state-disabled");
                $(this).find(".k-grid-SignUp").text("Awarded");
            },
            error: function () {
                alert('Failed  ' + result);
                
            }
        })
    }

1 Answer, 1 is accepted

Sort by
0
Accepted
Petar
Telerik team
answered on 13 Jun 2022, 09:02 AM

Hi, Scott.

Here is a REPL example demonstrating how the targeted functionality can be implemented. The example uses this method to disable the clicked custom command button:

function SignUp(e) {
    $(e.currentTarget).addClass("k-disabled");
    $(e.currentTarget).text("Awarded");
}

Using the suggested approach, you can execute similar code when the Ajax request in your scenario is successful.

I hope the above details will help you achieve what you need. 

Regards,
Petar
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Scott
Top achievements
Rank 1
commented on 14 Jun 2022, 12:26 AM

Thank you sir
Petar
Telerik team
commented on 14 Jun 2022, 06:03 AM

You are welcome, Scott! I am happy to hear the suggested approach has helped you. 
Tags
Grid
Asked by
Scott
Top achievements
Rank 1
Answers by
Petar
Telerik team
Share this question
or