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

How to set Grid ForeignKey column nullable

1 Answer 744 Views
Grid
This is a migrated thread and some comments may be shown as answers.
K'Library
Top achievements
Rank 1
K'Library asked on 23 Sep 2017, 06:06 AM

Hi,

I want to use Grid ForeignKey column to choose objects by id.

The sample is in attachment. I want to make school column and grade column nullable, and I can set the value to null when I edit the row.

How to do this?

 

If I want to choose school column value by typing characters for filtering, is it possible to do this in Grid ForeignKey column? Or I have to use ClientTemplate to solve this problem? 

 

Because the sample file exceed the maximum size, I removed Telerik js/css files from the sample, please use version 2017.3.913

 

1 Answer, 1 is accepted

Sort by
1
Georgi
Telerik team
answered on 26 Sep 2017, 12:42 PM
Hi Keith,

Possible solution is to define custom drop down editor and enable the value primitive property in order for the model to be updated correctly when the value is null. 

e.g.
@model object
     
@(Html.Kendo().DropDownListFor(m => m)
    .Name("Grade")
    .BindTo((IEnumerable<Grade>)ViewBag.Grades)
    .OptionLabel("No value")
    .ValuePrimitive(true)
)

For more information on  how to create custom editors, refer to the following article:



Regards,
Georgi
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
K'Library
Top achievements
Rank 1
Answers by
Georgi
Telerik team
Share this question
or