asp.net mvc - How do I have a client template that changes between edit and read mode in a Telerik MVC grid? -


i creating telerik mvc ui grid , 1 of properties in record view model numeric company id.

what want grid display display name company in column when reading grid, when creating new record (or editing existing record) show drop down possible values user can select.

i've done first part c.bound(x => x.companyid).clienttemplate('#= getcompanyname(companyid)#'); , works fine, don't see in examples or api reference on how have editing template different display template.

i'm sure missing something, since 1 example on telerik's own website shows (http://demos.telerik.com/aspnet-mvc/grid/editing-custom) source code show missing definition drop down box (easily seen in example passes categories viewdata element none of provided source code uses that.

any hints on i"m missing accomplish this?

edit:

ok, after bashing head against wall think want create shared editor template, column.bound(x => x.companyid).editortemplatename("idnamepairdropdown").editorviewdata(new { idnamepairs = model.availablecompanies });.

of course doesn't work, , gives me argumentnullreference exception though @ break viewdata["idnamepairs"] gives me correct non-null collection, @ least it's hint.

edit 2:

looks solution following in grid definition:

              c.bound(x => x.marketingcompanyid).title("marketer")                   .clienttemplate("#= getcompanyname(marketingcompanyid) #")                   .editortemplatename("idnamepairdropdown")                   .editorviewdata(new { idnamepairs = model.availablecompanies, idnamepairname = "marketing_companies" }); 

then create corrosponding editor template in ~/views/shared/editortemplates/idnamepairdropdown.cshtml

@using system.collections

@(html.kendo().dropdownlist()       .name("id_pair_dropdown_" + viewdata["idnamepairname"])       .datavaluefield("id")        .datatextfield("name")       .htmlattributes(new { data_value_primitive = "true"})       .bindto((ienumerable) viewdata["idnamepairs"]))) 

this correctly allows distinct drop down per column when in edit mode.

the missing part how save output, selecting value in drop down , clicking update button returns default value of column.

i know old question since doesn't have answer, thought give one. 1 needs define column foriegnkey column , provide editor template it. here column definition works in 1 of grids:

col.foreignkey(c => c.typeid_kendogrid, (ienumerable<selectlistitem>)viewbag.producttypes, "value", "text").title("type").width(150); 

then editor template (which think included in kendo package) in file called gridforeignkey.cshtml:

@model object  @(  html.kendo().dropdownlistfor(m => m)                            .bindto((selectlist)viewdata[viewdata.templateinfo.getfullhtmlfieldname("") + "_data"])     .filter(filtertype.contains)   ) 

you may notice property name looks little funky (typeid_kendogrid). that's because in case field nullable , grid had difficult time binding null it. in viewmodel class this:

public string typeid_kendogrid     {                 {             return this.typeid.tostring();         }         set         {             int i;             this.typeid = int.tryparse(value, out i) ? (int?)i : null;         }     } 

where model property typeid.


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -