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

DropDownList valueMapper for FK columns

2 Answers 216 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Austen
Top achievements
Rank 1
Austen asked on 20 Dec 2018, 01:01 AM

Hello everyone,

I have a dynamic Kendo grid that can perform CRUD operations. Foreign Keys are retrieved and mapped to their value and placed in the grid as a drop down list using an editor template, similar to this example here: https://demos.telerik.com/kendo-ui/grid/foreignkeycolumn

I have virtualization enabled on those FK dropdowns similar to this example: https://demos.telerik.com/kendo-ui/dropdownlist/virtualization and my dropdown correctly calls the valueMapper with the id. The problem is with the valueMapper, as this function only receives the FK id or dataitem. I am not able to communicate to the server which column the FK id belongs to, and thus can not return the index of the value. This problem seems that it could result in any grid that has multiple foreign keys so I am hoping there is a solution but I have been unable to find one. Any tips/leads would be greatly appreciated!

Here is my DynamicForeignKey editor template that is used as in each FK column of the grid.

@(
     Html.Kendo().DropDownListFor(m => m)
            .Filter(FilterType.Contains)
            .HtmlAttributes(new { style = "width:300px" })
            .Height(290)
            .DataValueField("ForeignKeyID")
            .DataTextField("ForeignKeyName")
            .DataSource(source =>
            {
                source.Custom()
                    .ServerFiltering(true)
                    .ServerPaging(true)
                    .PageSize(80)
                    .Type("aspnetmvc-ajax")
                    .Transport(transport =>
                    {
                        transport.Read("Read", "ForeignKey", new { SchemaName = ViewData["SchemaName"], TableName = ViewData["TableName"], ColumnName = ViewData["ColumnName"] });
                    });
            })
            .Virtual(v => v.ItemHeight(26).ValueMapper("valueMapper"))
)

2 Answers, 1 is accepted

Sort by
0
Accepted
Ivan Danchev
Telerik team
answered on 21 Dec 2018, 04:04 PM
Hello,

If you need to send additional data to the server you could consider using the DataSource transport.data function. Let us know whether that works in your scenario.

Regards,
Ivan Danchev
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
Austen
Top achievements
Rank 1
answered on 28 Dec 2018, 12:02 AM

Hello Ivan,

Thanks for the response. I ended up modifying the valueMapper ajax call with the additional parameters needed, along with the column name that I store by using the grids Edit event. For anyone else this is my Edit event call:

function onEdit(e) {
    var container = e.container;
    var dropDownList = container.find("[data-role=dropdownlist]").data("kendoDropDownList");
    if (dropDownList) COLUMNNAME = dropDownList.element[0].id;
}
Tags
DropDownList
Asked by
Austen
Top achievements
Rank 1
Answers by
Ivan Danchev
Telerik team
Austen
Top achievements
Rank 1
Share this question
or