0
votes

Is it possible to have a Kendo Grid where the model being edited from the edit command, or even a custom command, is different than the model being listed in the grid itself?

Essentially I need to have the grid displaying a list of one type of ViewModel that contains a customer IDs and an email address. When the user clicks the edit button, the form would allow them to batch add/remove emails for the customer ID of the row they clicked edit from.

Every time I try to do something like this, the popup throws an error that is received the incorrect model type.

1

1 Answers

0
votes

I'm not 100% sure what you want to do. You say your ViewModel has an ID and email address but you want to batch add email addresses. I'm assuming theres multiple emails but either way, my answer should answer any custom edit scenario.

You would have to handle it yourself. Kendo does not have anything like this out of the box.

What I started doing is this:

  • Add your custom command as a template
  • Add the ID of the model in the button and a class to find this button <button class="custom-edit" data-targetid="#=Id#">Custom Edit</button>
  • Open a window when you click that button (I personally prefer some standard jQuery's $.on() to listen to the event)

myGrid.element.on("click", ".custom-edit", function(ev){
    ev.preventDefault(); // In case your grid is in a form
    // Personally I just call an action that returns me a partial view with the ID as parameter and turn it into a window. You then bind to the window's close event to refresh the grid and destroy the window (unless you want to use the same window and just reload it)
});