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

Problem binding nullable value to dropdown in grid

15 Answers 1553 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Brian Roth
Top achievements
Rank 1
Brian Roth asked on 23 Apr 2012, 10:33 PM
Hello All,

I'm using a batch edit grid with an editor template that is very similar to the editor template demo on your site.  I'm getting some strange behavior when editing the dropdownlist cell.  The difference between my situation and the demo is that ProductID in the demo is a non-nullable numeric column, but in my case it is nullable.  I am capturing the grid save event just to verify that something is happening.  It works fine when editing a cell that already has a value selected for ProductID.  But for new rows or for cells where there is no ProductID changing the value doesn't persist the change back to the grid.  The save event doesn't fire in this case.  If I update my model so that the property is non-nullable and returns a value of -1 where I would have been returning a null then it works.  So it feels like there's some weird behavior with the DropDownList, but maybe there is something I'm doing wrong.  Let me know if you have any ideas.

My source code is pretty messy right now, but I could try to hack up the editor demo to match my situation if that would help.

Thanks,
Brian

15 Answers, 1 is accepted

Sort by
0
Iliana Dyankova
Telerik team
answered on 26 Apr 2012, 04:31 PM
Hello Brian,

I am not pretty sure where the problem comes from. Could you please send us a simple test project which reproduces the depicted issue? Thus I will be able to observe the problem and advice you further.

Greetings,
Iliana Nikolova
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Brian Roth
Top achievements
Rank 1
answered on 02 May 2012, 11:37 PM
Hi Iliana,

Sorry for the delayed reply.  I'm still working on stripping down our project to a simple example.  I tried modifying the grid template demo page, but couldn't reproduce the problem with a similar situation.  The only difference was in the demo page I had a hard coded data source, but for my project I'm using Microsoft MVC and getting the data through controller calls.  So it may be an interaction with MVC and KendoUI (or it may just be something I'm doing wrong).  Anyway, I'm working on putting together a small MVC project for you to test with.  I hope to have something by the end of the week.

Thanks,
Brian
0
Brian Roth
Top achievements
Rank 1
answered on 08 May 2012, 05:09 PM
Hi Iliana,

I was finally able to put together a stripped down example of the problem I'm seeing.  I created an ASP.Net MVC project with a SQL Express database.  I have two tables - Department and Division.  Both tables use an autogenerated integer column as an Id.  On the main page of the website there is a grid showing all the departments.  There is a column that shows the division and a custom editor for that column that uses a KendoDropDownList.  The dropdown text is bound to the Division Name and the value is bound to the Division Id.  DivisionId is a nullable integer property on the Department model.  The department updates correctly when changing from one Division to another or from a Division to no division.  But where it's failing is changing from no division to a value or in trying to set the division on a new record.  So it seems like the problem is related to having the dropdownlist bound to a null value. 

The project is about 8MB in size when zipped, so I am unable to attach it here.  Please let me know the best way to get it to you.  Thanks!

Regards,
Brian
0
Brian Roth
Top achievements
Rank 1
answered on 08 May 2012, 05:37 PM
I was able to clean the solution and get it down to a reasonable size.  Here it is.  Let me know if you have any trouble getting it to run.  Thanks!
0
Iliana Dyankova
Telerik team
answered on 10 May 2012, 05:37 PM
Hello Brian,

Thank you for sending your simplified project. The problem occurs because the DivisionId property is Nullable and in such scenario you should use an object. For convenience I updated the project and attached it back.

Kind regards,
Iliana Nikolova
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Brian Roth
Top achievements
Rank 1
answered on 10 May 2012, 11:13 PM
Hi Iliana,

Thanks so much for the updated project!  I was able to make the corresponding changes in my real project and get things working.  I just have one more thing to work through, and I'm not sure if it's possible or not.  I have filtering enabled on the grid and would like to have the capability to filter the Division column.  Currently if I click on the filter it pops up a filter dialog that has nothing selectable.  I'm guessing that's because the type is an object instead of a string or number.  Is there a way to have this dialog have the same selections as a string column (starts with, contains, etc.)?  We're handling all the paging/sorting/filtering server side so we should be able to write code to handle filtering on the sub-object properties.

Thanks,
Brian
0
Iliana Dyankova
Telerik team
answered on 11 May 2012, 04:23 PM
Hello Brian,

It is good to know that everything is working fine now. Regarding your other question - I am afraid that currently it is not possible to filter a field which is an object.

 

Greetings,
Iliana Nikolova
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Brian Roth
Top achievements
Rank 1
answered on 11 May 2012, 04:30 PM
Thanks for the quick reply.  I posted a suggestion in the User Voice for the filtering.  In the meantime, I'll see if I can implement some sort of custom filter with some jQuery logic.

Thanks again,
Brian
0
Iliana Dyankova
Telerik team
answered on 15 May 2012, 01:03 PM
Hi Brian,

I discussed your scenario with my colleagues and as a possible workaround I would suggest the following approach:
  • In the definition of the grid columns bind the field which will be filtered (for example DivisionId) and in the DropDown editor for this column bind the Division object;
  • In case you use Kendo UI filtering you need in the save event of the grid to set the bind field (Ex. DivisionId) of the Division object to the bind column.   

Also, I updated your project to illustrate this approach in action, but some changed in the server logic are needed. Please try this solution and let me know if everything works fine. 


Kind regards,
Iliana Nikolova
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Brian Roth
Top achievements
Rank 1
answered on 15 May 2012, 11:17 PM
Hi Iliana,

Is that the latest version of the project?  I downloaded it and didn't see any differences.  I'm excited to try it out!

Thanks,
Brian
0
Iliana Dyankova
Telerik team
answered on 16 May 2012, 12:28 PM
Hello Brian,

Please excuse me - it seems that I attached the previous version of the project by mistake. Here is the latest one.

 
Regards,
Iliana Nikolova
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Brian Roth
Top achievements
Rank 1
answered on 16 May 2012, 07:45 PM
Hi Iliana,

Thanks for the example!  I was able to rework my server-side logic to get things working.  I updated the view to bind to a DivisionName property from the model, which just returns the value of Division.Name.  I tried binding the grid column directly to Division.Name and that worked for sorting and filtering, but would error out when going into edit mode.  Is this expected behavior or is this an issue with the kendo code? 

I've got some more work to do to make the overall functionality more generic for my project, but here is an updated version that has everything working.

Thanks again for all your help.

Regards,
Brian
0
Iliana Dyankova
Telerik team
answered on 21 May 2012, 05:34 PM
Hello Brian,

I tried to reproduce the issue locally, but to no avail. Could you please list all steps you performed in order to reproduce the problem? This will help us get a better idea what might be causing it. 
 
Kind regards,
Iliana Nikolova
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Brian Roth
Top achievements
Rank 1
answered on 21 May 2012, 05:51 PM
Hi Iliana,

Thanks for looking into this.  With the project I uploaded last week, I was able to get the application to error if I change line 106 in Index.cshtml to the following.  Basically changing the field from "DivisionName" to "Division.Name":

{ field: "Division.Name", title: "Division", editor: divisionDropDownEditor, template: '#=Division ? Division.Name : "" #' },

The grid comes up fine and sorting and filtering work, but when I click on a Division cell to edit the data I get an error "Unable to get value of the property 'type': object is null or undefined"

Hopefully that helps you in reproducing the problem.  Thanks!

Regards,
Brian
0
Georgi Krustev
Telerik team
answered on 25 May 2012, 08:59 AM
Hello Brian ,

 
The editing of the Grid widget does not support nested models. I will suggest you use the latest test project, which Iliana send you.

Regards,
Georgi Krustev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Brian Roth
Top achievements
Rank 1
Answers by
Iliana Dyankova
Telerik team
Brian Roth
Top achievements
Rank 1
Georgi Krustev
Telerik team
Share this question
or