0

I have a Kendo UI grid which uses a dropdown as the editor for a field. I'm having problems getting the dropdown to properly bind to the viewModel (at least I think that is the issue). If I make a selection from the dropdown then add a new row or navigate from the row I am on, the field shows [object Object]. Now if I go back to the row and make a different selection and navigate to a different row, it behaves like it should, showing the selection I made. Here is a js bin showing the behavior.

1 Answer 1

3

The problem is SuggestedVendor type is string but when you click Add New Line Item link to add new item you set some default value Id: 1, Position: 1 and SuggestedVendor : null but it should empty string like SuggestedVendor : ''

dataSource.add({ Id: 1, SuggestedVendor: (viewModel.suggestedVendor === null) ? '' /* instead of null*/ : viewModel.suggestedVendor.SuggestedVendor, Position:1 });

Working demo

Note: You can set your default value during datasource field declaration, for more details demo for custom editing. In this way you don't need manually handle $(".k-grid-custom-create").on("click", function (e) {...})

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks that was it. As for defaulting the value in the datasource declaration, I have tried that but I can't find a way to do this dynamically. My app is for creating requisitions and if the user didn't select a default Suggested Vendor when creating the Header (which is bound to viewModel.suggestedVendor) then I leave it blank. I have found that setting the default in the datasorce only allows hardcoding it. If you know of a way to dynamically set it, I would like to see a working example. Thanks again!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.