2
votes

I'd appreciate any help.

I have a Kendo grid with incell editing mode:

 @(Html.Kendo().Grid(Model.ContractCurrencyClauses)
                          .Name("ContractCurrencyClauses")
                          .ToolBar(toolbar => { toolbar.Create(); })
                          .Columns(columns =>
                          {  
                              columns.Bound(p => p.CLAUSE).ClientTemplate("#= CLAUSE #" +
                               "<input type='hidden' name='ContractCurrencyClauses[#= index(data)#].CLAUSE' value='#= CLAUSE #' />"
                              ).EditorTemplateName("CurrencyClause");

                              columns.Command(command => { command.Destroy(); });
                          })
                        .Editable(editable => editable.Mode(GridEditMode.InCell))
                        .DataSource(dataSource =>
                            dataSource.Ajax()
                            .Model(model =>
                            {
                              ...
                            })
                            .ServerOperation(false)
                            )
            )

Index function:

function index(dataItem) {
    var data = $("#ContractCurrencyClauses").data("kendoGrid").dataSource.data();        
    return data.indexOf(dataItem);
}

The column CLAUSE has EditorTemplate:

@model int?

@(Html.Kendo().ComboBoxFor(model=>model).BindTo((SelectList)(new SelectList(context.CurrencyClauses, "CODE", "TITLE", Model))))

The problem is when I select some item from the drop down the index() function receives null, instead how can I bind selected index?

1
Did you found any solution to the NULL problem? - Junior

1 Answers

3
votes

Hey Gvuzal Rakhmaveva,

there is one solution i want to share with you..

you must give the combo box name property the same name as the property you need to bind to.you set the property [UIHint("TemplateName")] on field in the view model. Added the template in the shared/EditorTemplates folder. Now it binds and works fine with the refresh.

-------------------Grid-------------------------------

@(Html.Kendo().Grid<MVC.ViewModels.ResultsViewModel>(Model)    
                        .Name("Grid")    
                        .Columns(columns => {                         
                            columns.Bound(o => o.Waarneming).Width(550).Title("Waarneming");                                            columns.Bound(p => p.Result).Width(110).Title("Resultaat");                                                                            
                        })                                      

-------------------Combo Box----------------------

@(Html.Kendo().ComboBox()
.Name("Result") 
.DataValueField("Text")
.DataTextField("Text") 
.HighlightFirst(true)    
.BindTo((IEnumerable<SelectListItem>) ViewBag.NormeringList) 

)

I hope this help you.

if work then don't forget to give vote.