Determine the type of the sender

1 Answer 386 Views
General Discussions
Dan
Top achievements
Rank 1
Iron
Iron
Veteran
Dan asked on 26 Jan 2022, 03:36 PM
I have a databound event that is used on grid but also on a treelist (at first it was grid). Is there a way to determine the type of the e.sender?

1 Answer, 1 is accepted

Sort by
0
Accepted
Martin
Telerik team
answered on 31 Jan 2022, 02:05 PM

Hello, Dan,

As both the TreeList and the Grid have their own dataBound event, the e.sender will always be the widget that is triggering the event. Could you please let me know if I am missing something from the question?

Regards,
Martin
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.

Dan
Top achievements
Rank 1
Iron
Iron
Veteran
commented on 31 Jan 2022, 02:14 PM | edited

Hi Martin,

You are missing exactly the question. Determine the type of the sender (if it is a Tree or a Grid)

Example

function dataBound(e) {
   console.log(typeof e.sender); // this is object
    if (e.sender ?? TreeList) {
        console.log("The event was triggered for a TreeList");
    } else if (e.sender ?? Grid) {
        console.log("The event was triggered for a Grid");
    }
}
I am using the same event cause the functionality should be the same but it seems that the 2 controls do not behave in the same way so for a TreeList I have to do some more work in order to have the same functionality as for a grid.
Martin
Telerik team
commented on 01 Feb 2022, 09:33 AM

You can whether the e.sender.options.name is "TreeList" or "Grid". Here is a small example for reference.
Tags
General Discussions
Asked by
Dan
Top achievements
Rank 1
Iron
Iron
Veteran
Answers by
Martin
Telerik team
Share this question
or