0

I have a Kendo grid with a Employee dropdown column, much like the examples that they provide. My dataset has a employee ID. I created a model that holds the employee object and deliver that to my view. Here's a snip of the controller code:

  select new 
 {
  ShiftDataID = g.Key.ShiftDataID,
  EmployeeID = g.Key.EmployeeID,
  Employee = (from e in dbContext.Employees
      where (e.EmployeeID == g.Key.EmployeeID)
      select new EmployeeDTO
      {
           EmployeeID = e.EmployeeID,
           EmployeeName = e.EmployeeName
       }).FirstOrDefault(),
   CaseCount = g.Key.CaseCount...

Here's the view:

@(Html.Kendo().Grid(Model)
.Name("ShiftDataGrid")
.Columns(columns =>
{
    columns.Bound(x => x.Employee).ClientTemplate("#=Employee.EmployeeName#").Title("Employee").Width(75);

(removed other columns for simplicity)

OK, so all is good. When the grid renders, it shows an employee column with the correct employee names. HOWEVER, when user clicks on the name to change it, I get the following:

enter image description here

So, my problem is that it's not rendering the drop-down list control, but the Employee objects properties. I'm not sure what I'm doing wrong, any help would be appreciate it.

Thanks, -Alex

AlexFreitas
  • 342
  • 4
  • 14
  • Could you post the code to generate the drop down list? The only code posted is to generate a Kendo grid that references a client template. – Metro Smurf May 17 '13 at 14:45
  • I was under the impression that if the bound column was a list, then kendo would convert that into a dropdown automatically using the build in templates. Do I need to build my own template for this? Sorry, I'm a Kendo newbie and inherited this site so I'm still trying to wrap my head around some of the concepts. – AlexFreitas May 17 '13 at 15:02
  • Without seeing more of the code, it's hard to say what's going on. However, take a look at this SO Post: [How can I set and get the value of a dropdownlist in a grid in Kendo UI MVC?](http://stackoverflow.com/q/11116542/9664) and review the [KendoUI Grid / Editing custom editor](http://demos.kendoui.com/web/grid/editing-custom.html). Both have examples of using a drop down list that may help. In the end, there needs to be some data source (list) related back to the column in question. – Metro Smurf May 17 '13 at 15:24
  • You were right, I was missing the dropdown template. The thing that is really throwing me off is that in the examples they call the Read/Update grid methods of the employee template, but in my code I have this huge grid that it's calling it's on methods. Do you know what I mean? I have now created a template for my employee list and added to my share folder. I should be able to just call the dropdown view code and pass a data source to it, correct? Or does the template have do have it's own controller? – AlexFreitas May 17 '13 at 16:58
  • 1
    The template should not require it's own controller; passing in the data source, as you've described, is the correct method, IMO. I've found with the Kendo UI that it's easier to start with a small piece of functionality and adding small chunks at a time. Trying to configure a grid and adding all the various options at one time is a bit daunting if you've not worked with the framework before. – Metro Smurf May 17 '13 at 18:15
  • Thanks MetroSmurf. I still don't quite have it. I am getting the drop-down now, but it's empty. I think it's because of how my page is laid out. I have a main page and the grid is actually on a partial view that loads via Ajax. I noticed that I load the list of employees to a ViewData variable but when it hits the template on the client the ViewData variable is null. There's only one controller that I use for the main page and for loading and updating the grid. I'll keep at it, I'm so close now.... – AlexFreitas May 17 '13 at 22:59
  • I figured out the problem I was having. My page was laid out with partial views. I just had to add the data source of the template to point to the right controller: .DataSource(dataSource => dataSource .Read(read => read.Action("GetEmployeeList", "ShiftData", new { ProductID = ViewData["employees"] }))) Thanks for your help MetroSmurf! – AlexFreitas May 18 '13 at 01:46
  • You should add this as an answer to the question, and accept it! It's encouraged to post your own solutions when you find them (right now, it's hidden by default because there are so many comments). – Hannele May 29 '13 at 17:19

0 Answers0