I have a series of complex update forms for various grids. These are not easily represented as editor templates. Much of the UI is variable and changes to the rendered form would have to be done with JavaScript.
Ideally, I would like to use popup editing but with the contents of the popup coming from a PartialView in an ajax call. Is this at all possible and is there a recommended way of doing it?
I managed to get part of the way to a solution but the final piece (saveRow() and cancelRow()) does not work.
Here is a rough outline of my method (grid BeforeEdit event):
01.var onBeforeEdit = function(e) {02. e.preventDefault();03. var grid = e.sender;04. 05. var url = "example/controller/action";06. 07. if ($("#generic-edit-dialog").length === 0) {08. $("body").append("<div id='generic-edit-dialog'></div>");09. }10. 11. var html ="<div id='generic-edit-dialog-content' class='dialog-content'></div>";12. html += "<div class='dialog-footer'><div class='pull-right'>";13. html += "<button type='button' id='generic-edit-update' class='btn btn-default k-button' data-role='button' role='button' aria-disabled='false'>Update</button>";14. html += "<button type='button' id='generic-edit-cancel' class='btn btn-default k-button' data-role='button' role='button' aria-disabled='false'>Cancel</button>";15. $("#generic-edit-dialog").html(html);16. 17. $.post(url, JSON.stringify(model))18. .done(function (data) {19. $("#generic-edit-dialog-content").html(data);20. 21. //Put in every element in the window data-bind="value:INPUT NAME" 22. //<input name="price" /> become <input name="price" data-bind="value: price" />23. $("#generic-edit-dialog-content [name]").each(function () {24. var name = $(this).attr("name")25. $(this).attr("data-bind", "value:" + name);26. });27. 28. kendo.bind($("#generic-edit-dialog-content"), model);29. 30. var win = $("#generic-edit-dialog").kendoWindow({31. width: width,32. title: title,33. modal: true,34. visible: false,35. actions: [36. "Close"37. ],38. close: function () { this.destroy; }39. }).data("kendoWindow");40. 41. $("#generic-edit-update").click(function () {42. grid.saveRow();43. win.close();44. });45. 46. $("#generic-edit-cancel").click(function () {47. grid.cancelRow();48. win.close();49. });50. 51. win.center().open();52. })53. .fail(function (jqXHR, textStatus, errorThrown) {54. alert("error: " + errorThrown);55. });56. 57.}
Stepping through the code, it seems that some things are missing which prevent saveRow() and cancelRow() from behaving as expected. In particular, there are references to grid._editContainer and grid.editable which are undefined in my case.
Is there anything to be done to salvage this?