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

Get button which raises edit event

3 Answers 349 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Markus
Top achievements
Rank 1
Markus asked on 09 Oct 2019, 01:21 PM

Hallo zusammen,

ich habe in meinem Grid zwei Knöpfe, die das edit event auslösen. Ich rufe damit das gleiche Popup auf, aber abhängig davon welcher Edit button geklickt wurde, müssen im Popup verschiedene Elemente ein- oder ausgeblendet werden. Ich habe noch keine Möglichkeit gefunden wie ich herausbekomme welcher Knopf geklickt wurde.

Beide Button befinden sich in der Toolbar
        .ToolBar(t =>
        {
            t.Create().Text("Add User");
            t.Create().Text("Add Host");
        }
 und das Event folgendermaße deklariert:
        .Events(events => events
            .Edit("insertPopupCaption")
        )

Kann mir hier bitte jemand weiterhelfen?

Kind regards
Markus

3 Answers, 1 is accepted

Sort by
0
Markus
Top achievements
Rank 1
answered on 10 Oct 2019, 08:05 AM
Sorry, I was so focused on the problem that I did not think to write in English.

I have two buttons in my grid that trigger the edit event. I'll call the same pop-up, but depending on which edit button was clicked, different elements must be shown or hidden in the popup. I still have not found a way how to find out which button was clicked.

Both buttons are located in the toolbar
         .ToolBar (t =>
         {
             t.Create (). text ("Add User");
             t.Create (). Text ("Add Host");
         }
  and declare the event as follows:
         Events (events => events
             .EDIT ("insertPopupCaption")
         )

Can someone help me here please?
0
Accepted
Nencho
Telerik team
answered on 11 Oct 2019, 10:54 AM

Hello Markus,

You can use custom buttons, and add classes to them, in order to be easy to hook click events. These events could be used to set a global variable, base on which, you can access for example a hidden field in the popup editor, and hence, store information regarding which button was clicked. Please see the below implementation:

@(Html.Kendo().Grid<KendoUIMVC5.Models.Person>().Name("persons")
    .DataSource(dataSource => dataSource
        .Ajax()
        .Model(model => model.Id(m => m.PersonID))
            .Read(read => read.Action("GetPersons", "Home"))
            .Update(up => up.Action("UpdatePerson", "Home"))
    )
    .Events(ev => ev.Edit("onEdit"))
    .Columns(columns =>
    {
        columns.Bound(c => c.PersonID).Width(200);
        columns.Bound(c => c.Name);
        columns.Bound(c => c.BirthDate).Format("{0:g}");
        columns.Command(cmd => cmd.Edit());
    })
    .ToolBar(t =>
    {
        t.Custom().Text("Add User").HtmlAttributes(new { @class = "addUser" }); ;
        t.Custom().Text("Add Host").HtmlAttributes(new { @class = "addHost" });
    })

    .Pageable()
    .Sortable()
    .Editable(ed => ed.Mode(GridEditMode.PopUp).TemplateName("Person"))
)

<script>
    var isAddUserClick;
    $(document).ready(function () {
        $(".addUser").click(function (e) {
            e.preventDefault();
            isAddUserClick = true;
            $("#persons").getKendoGrid().addRow();
        })
        $(".addHost").click(function () {
            e.preventDefault();
            isAddUserClick = false;
            $("#persons").getKendoGrid().addRow();
        })
    })
    function onEdit(e) {       
        if (isAddUserClick) {
            $("#hidden1").val("UserisClick");
        }
        else {
             $("#hidden1").val("UserisNOTClick");
        }
    }
</script>

// popup editor:
<input type="hidden" id="hidden1" name="name" value="" />

 Hope this would help.

Regards,
Nencho
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Markus
Top achievements
Rank 1
answered on 15 Oct 2019, 12:36 PM

Hi Nencho,

sometimes it's easier than you think.

Work's like a charm.

Many thanks.

Greetings
Markus

 

 

Tags
Grid
Asked by
Markus
Top achievements
Rank 1
Answers by
Markus
Top achievements
Rank 1
Nencho
Telerik team
Share this question
or