How to access the native editor for a foreign key column in a Kendo Grid

1 Answer 136 Views
Grid
Travis
Top achievements
Rank 1
Iron
Travis asked on 11 Sep 2022, 04:43 PM

Howdy!

I have a scenario in which I need to run some code when the item selected in a foreign key column in my grid is changed when it is being edited.

I can access other columns' editors without issue, but for some reason, every time I attempt to grab the editor for the foreign key column, it comes up as null.

For instance, I can use the following to grab the numeric text box for the edited row (in the Grid's on-edit event) with no issues:

var mcEditor = e.container.find("input[name=MoistureContent]").data("kendoNumericTextBox");

But, the only thing I can get to return as an object in the same on-edit event of the grid is the following:

var proctorEditor = e.container.find("input[name=ProctorReportId]");

I've tried using the following with no luck:

var proctorEditor = e.container.find("input[name=ProctorReportId]").data("kendoDropDownList");
var proctorEditor = e.container.find("input[name=ProctorReportId]").data("kendoComboBox");
The two instances above return null objects. But, as I mentioned, everything up until the call to .data() works. I'm at a loss of what the correct value to pass to the data() method should be to return the editor for the foreign key column in the grid.

1 Answer, 1 is accepted

Sort by
0
Travis
Top achievements
Rank 1
Iron
answered on 11 Sep 2022, 07:23 PM

It turns out the problem was that I was finding an input tag instead of a select tag. The correct code should be:

var proctorEditor = e.container.find("select[name=ProctorReportId]").data("kendoDropDownList");
Making that change let the code work as expected.
Mihaela
Telerik team
commented on 14 Sep 2022, 03:17 PM

Hi Travis,

You are right - the foreign key column in the Grid generates a DropDownList editor, which is created through a <select> element. This is the correct way to reference the DropDownList editor when the data cell is in edit mode.

If any further questions arise, don't hesitate to let me know.

Travis
Top achievements
Rank 1
Iron
commented on 14 Sep 2022, 03:24 PM

Yes. However, I could not find that particular piece of information anywhere in the documentation or samples for the Telerik UI for ASP.NET Core, so it was immensely more difficult to find the right solution than it needed to be.

I would like to suggest that as a standard practice, the documentation include examples of properly referencing each piece of the grid from javascript so it's much easier to find the appropriate solution when needed: I wasted close to half a day beating my head against the wall trying to figure this one out and if there had been documentation and/or examples showing how to reference a foreign key column in javascript, I could have reduced that time to a few minutes or so...
Mihaela
Telerik team
commented on 19 Sep 2022, 06:42 AM

Thank you for your feedback, Travis.

Completely agree with your suggestion, and we will consider it while working on the documentation improvement. If you have any other recommendations, don't hesitate to share them.

 

Tags
Grid
Asked by
Travis
Top achievements
Rank 1
Iron
Answers by
Travis
Top achievements
Rank 1
Iron
Share this question
or