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

Foreign Key Fields with null values

3 Answers 672 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kevin
Top achievements
Rank 1
Kevin asked on 30 Jul 2014, 09:39 AM
Hello,

I have to create a foreign key field, but the field can be null. so in the example below I cant change the row with the null value with the drop down.

How can I fix that ?

Please help me!

br,
Kevin A1Telekom Austria AG

01.<!DOCTYPE html>
02.<html>
03.<head>
05.    <style>html { font-size: 12px; font-family: Arial, Helvetica, sans-serif; }</style>
06.    <title></title>
07.    <link href="http://cdn.kendostatic.com/2014.2.716/styles/kendo.common.min.css" rel="stylesheet" />
08.    <link href="http://cdn.kendostatic.com/2014.2.716/styles/kendo.metro.min.css" rel="stylesheet" />
09.    <link href="http://cdn.kendostatic.com/2014.2.716/styles/kendo.dataviz.min.css" rel="stylesheet" />
12. 
14.</head>
15.<body>
16.            <script src="../content/shared/js/products.js" type="text/javascript"></script>
17.        <div id="example">
18.            <div id="grid"></div>
19. 
20.            <script>
21.                    
22.                     var categories = [{
23.        'value': null,
24.        'text': 'null'
25.    },{
26.        'value': 1,
27.        'text': 'Cat1'
28.    },{
29.        'value': 2,
30.        'text': 'Cat2'
31.    },{
32.        'value': 3,
33.        'text': 'Cat3'
34.    }];
35.               
36.            
37.               
38.$(document).ready(function () {
39.   
40.   
41.  var date = [{id: 1, name: "Jane Doe", category: 1},
42.             {id: 2, name: "XXX", category: 1},
43.             {id: 3, name: "XX2", category: null},
44.             {id: 4, name: "XXX3", category: 1},
45.             {id: 5, name: "XXX4", category: 3}];
46.   
47. var dataSource = new kendo.data.DataSource({
48.                        pageSize: 20,
49.    data: date,
50.                        schema: {
51.                            model: {
52.                                id: "id",
53.                                fields: {
54.                                  name: { type:'string' },
55.                                    category: { field: "category", type: "number" },
56.                                     
57.                                }
58.                            }
59.                        }
60.                    });
61.   
62.   
63.   
64.$('#grid').kendoGrid({
65.    dataSource: dataSource,
66.    height: 570,
67.    filterable: true,
68.    sortable: true,
69.    pageable: true,
70.    editable: true,
71.    toolbar: ['save', 'cancel'],
72.    columns: [
73.{ field: "name", title: "Name" },
74.     { field: 'category', title: 'Category', width: '200px', values: categories , }
75.        ]
76.    });
77.});
78. 
79.               
80.               
81.               
82.               
83.            </script>
84.        </div>
85. 
86. 
87.</body>
88.</html>

3 Answers, 1 is accepted

Sort by
0
Vladimir Iliev
Telerik team
answered on 01 Aug 2014, 06:43 AM
Hi Kevin,

Basically you should define custom editor for the column in order to set the "valuePrimitive" option of the dropDownList to true. For convenience I updated the provided example to work as expected:
Regards,
Vladimir Iliev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Hannah
Top achievements
Rank 2
answered on 16 Jan 2019, 09:20 PM

Vladimir,

I realize this is an old post, but I was wondering if you could make the 'ForeignKeyColumn: allow null values' example available again.

Regards,

Hannah

0
Georgi
Telerik team
answered on 18 Jan 2019, 02:15 PM
Hello Hannah,

I have tested the provided by my colleague sample and it seems to be working as expected on my end.

Nevertheless I have created a new dojo with the same content, you will find it in the link below:


Please test it and let me know if it works for you.


Regards,
Georgi
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.
Tags
Grid
Asked by
Kevin
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
Hannah
Top achievements
Rank 2
Georgi
Telerik team
Share this question
or