This is a migrated thread and some comments may be shown as answers.
Bind value member with GridColumn to set ID in ViewModel
1 Answer 55 Views
This is a migrated thread and some comments may be shown as answers.
Mudit
Top achievements
Rank 1
Veteran
Mudit asked on 01 May 2020, 11:19 AM

     Hi All

 

We are new to Kendo, hence this might be a simple scenario that we are not able to get around.

 

We have a grid, in which Employee Name column is actually a DropDown selection with in column that uses DropDownFor. We initially bound our column to Employee Object in the Model, but then Filtering, Export to Excel etc features didn't work. Upon some research we found that we need to bind to a view model that has only basic data types and not any complex data types.

We then created a view model on top of our Model and bind that to grid, but doing this we have lost the Employee Id which was earlier being set properly. Grid now shows Employee Name only which is not a unique field, we need to know the ID of selected member.

 

Can you please help us understand how we bind an object to column and still preserve all features of the grid like Filtering etc. 

If that is not possible can you suggest a way where in we can set ID of selected employee within viewmodel and not just name.

 

Please let me know if I can explain any further.

 

Thanks

M.

1 Answer, 1 is accepted

Sort by
0
Tsvetomir
Telerik team
answered on 05 May 2020, 10:45 AM

Hi Mudit,

In general, it is not mandatory to completely substitute the object field with primitive data. You could specify which property should be used for filtering, sorting, and visualization:

columns.Bound(c=>c.Category.CategoryName);

This way, you would access to both properties via the Category object.

In order for the editing to work, you should add the following in the EditorTemplate:

.HtmlAttributes(new { data_bind="value: Category" })

I hope you find this helpful.

 

Regards,
Tsvetomir
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
Grid
Asked by
Mudit
Top achievements
Rank 1
Veteran
Answers by
Tsvetomir
Telerik team
Share this question
or