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

Custom Editor (Dropdown) not sending default values on CRUD add

1 Answer 172 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Paul Sheridan
Top achievements
Rank 1
Paul Sheridan asked on 14 Aug 2012, 08:06 PM
I've run into a problem insofar as I've managed to get a complex foreign key editor to work with basic CRUD on the grid. However, upon adding new rows, if the drop downs are left unchanged from their initial state, no data is sent to the server for the add, showing 'undefined' in the colums and sending nulls to the add method.

I'm sure this is something to do with the defaultValue option on the model but can't find any reference on the forums

any help appreciated.

VS2012 project attached.

1 Answer, 1 is accepted

Sort by
0
Todd
Top achievements
Rank 1
answered on 31 Oct 2012, 04:16 AM
I had the same problem, and I can tell you It definitely has to do with setting defaultValue on the model field.  Also, you need to have that field defined as "number" if your values are integers.  When you set defaultValue, you can set it to either an integer or to a nested property if your model field is a "complex field" (.Net class or enum).  If it's a class or enum, you can do this: defaultValue: { MyField.MyValue }  (not sure if you need the extra curly braces)  ....and if it's a regular integer, you can do something like: defaultValue: 21

Without setting defaultValue, then new records will be sent to the server with null/zero values for these fields.

Telerik's own demo called "ForeignKey" grid demo is missing this defaultValue, so when you try to add a new row, you can not select the first drop-down value.  Shame, because this demo shows the best way to implement drop-downs in a grid cell.  I first used custom cell drop-down editors, but this is what I use now because it builds the drop-down for you.
Tags
Grid
Asked by
Paul Sheridan
Top achievements
Rank 1
Answers by
Todd
Top achievements
Rank 1
Share this question
or