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

ForeignKey column does not use GridForeignKey editor

3 Answers 63 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Boardy
Top achievements
Rank 1
Veteran
Boardy asked on 15 Jul 2020, 10:12 AM

I am setting up an editible grid and want to use the datasource version of the ForeinKey column.

columns.ForeignKey(d => d.AbbreviationId, ds => ds.Read(r => r.Action("GetAbbreviations", "API/Enum")), "Id", "Description").Width(100);

 

The dropdown list in the grid is filled properly etc., but the dropdown itself is not AutoWidth(true). To make this happen, I edited the GridForeignKey editor template. This does however not effect the dropdown.

When tested with a foreign key column that is filled via the ViewData[], this has the desired effect.

3 Answers, 1 is accepted

Sort by
0
Tsvetomir
Telerik team
answered on 17 Jul 2020, 08:56 AM

Hi Herre,

Indeed, the AutoWidth property might not behave as expected due to the fact that the cell is the parent of the DropDownList widget. Since the AutoWidth applies CSS styles, those styles are dependent on the parent container. Since the cell is not wide enough, the popup appears to not be adjusted. What I can recommend is that you apply an explicit width to the container. 

<style>
    .k-list-scroller {
        position:absolute;
        display: block;
        overflow-x:hidden;
        width:150px;
    }

    .k-list-container {
        width: 150px !important;
    }
</style>

 

Regards,
Tsvetomir
Progress Telerik

0
Boardy
Top achievements
Rank 1
Veteran
answered on 17 Jul 2020, 09:16 AM

Find the difference attached:

- Dropdown_FK is when using a datasource.

- Dropdown_VD is when passing the data via ViewData

So it works in the second case, but not in the first. I prefer not having to set an arbitrary width in the hope it will display properly, so for now I will stick to the ViewData version.

0
Tsvetomir
Telerik team
answered on 21 Jul 2020, 08:00 AM

Hello,

Indeed, the different behavior could be observed due to the fact that the GridForeignKey editor is not getting used. Therefore, setting the autoWidth option would not have a difference. An explicit editor could not be specified at the moment, however, we are working on making this possible. 

The only option is to override the options of the DropDownList within the edit event handler of the grid. Or, to use the CSS from my previous response. 

Let me know if you need more information on the approach for setting the options in the edit event.

 

Kind regards,
Tsvetomir
Progress Telerik

Tags
Grid
Asked by
Boardy
Top achievements
Rank 1
Veteran
Answers by
Tsvetomir
Telerik team
Boardy
Top achievements
Rank 1
Veteran
Share this question
or