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

Pass Model to column ClientTemplate editor in Grid

1 Answer 441 Views
Grid
This is a migrated thread and some comments may be shown as answers.
GCS
Top achievements
Rank 1
GCS asked on 02 Jul 2014, 11:50 PM
I have a grid whereas the columns are defined as: 

.Columns(columns =>
{
    columns.Bound(b => b.Field);
    columns.Bound(b => b.OldValue);
    columns.Bound(b => b.NewValue);
    columns.Bound(b => b.DateImported).Format("{0:dd-MMM-yyyy}");
    columns.Bound(b => b.BuildingChangeValidationStatusType).ClientTemplate("#=BuildingChangeValidationStatusType.Value#").Width(250);
    columns.Command(command => command.Custom("Update").Click("updateValidation"));
    columns.Command(command => { command.Edit(); }).Width(172);
})

The BuildingChangeValidationStatusType client template is defined as: 

@model Rep.Models.BuildingChangeValidationViewModel
@(Html.Kendo().DropDownList()
    .Name("BuildingChangeValidationStatusType") // Name of the widget should be the same as the name of the property
    .DataValueField("Id")
    .DataTextField("Value")
    .BindTo((System.Collections.IEnumerable)Model.BuildingChangeValidationStatuses)
)


I am wanting to pass the model for each row to the client template since each row will contain its own lookup values.  How can I accomplish this? 

1 Answer, 1 is accepted

Sort by
0
Vladimir Iliev
Telerik team
answered on 07 Jul 2014, 07:13 AM
Hi Dave,

From the provided information it's not clear for us what exactly you are trying to achieve and what is the current Grid configuration that you are using, however if you need to filter the DropDownLists based on current model than you can use the following approach:
- Set DataBound event handler:
.Events(e => e.DataBound("dataBound"))

- Add the event handler before DropDownList initialization code:
<script>   
    var globalFlag = false;
    function dataBound(e) {
        //execute only once
        if (!globalFlag) {
            var row = this.wrapper.closest("tr");
            var grid = row.closest("[data-role=grid]").data("kendoGrid");
            var model = grid.dataItem(row);
            globalFlag = true;
            this.dataSource.filter({ field: "Text", operator: "startswith", value: "Ax" });
        }
    }
</script>
       
@(Html.Kendo().DropDownList()

Regards,
Vladimir Iliev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
GCS
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
Share this question
or