I have a KendoUI Grid set up and working pretty nicely. My team and I finally figured out how to get all the CRUD stuff working, but we're having an issue when confronted with the custom popup editor.
We have a nice custom editor set up and it works perfectly for Edit mode. We only want certain fields to be editable for existing entries, and want different fields editable for new entries. For example, we have a database of team members on a project with the following schema model:
When editing an existing entry in the grid, only empRole and isCore should be editable.
When adding a new entry to the grid, only empLastName, empFirstName, empRole, and isCore should be editable.
The rest should appear as either standard text or greyed-out checkboxes. I am aware that I can simply make all fields inputs and the plugin will automatically filter out which fields accept input and which do not upon submission, but that is undesirable behaviour. We wish to make it visually clear that certain fields are not editable, while being able to have different fields be editable in different scenarios (Add vs Edit).
Is this possible? We really need to find a way to make it possible if it isn't.
Here's the editor template we have so far:
Here's our DataSource declaration:
Here's our kendoGrid declaration:
Here's our rowTemplate:
Any assistance that can be provided would be most appreciated.
Thank you for your time and screen space. :)
We have a nice custom editor set up and it works perfectly for Edit mode. We only want certain fields to be editable for existing entries, and want different fields editable for new entries. For example, we have a database of team members on a project with the following schema model:
model: { id: "empId", fields: { "empId": { editable: false, type: "string" }, "empLastName": { editable: false, type: "string" }, "empFirstName": { editable: false, type: "string" }, "empRole": { editable: true, type: "string" }, "empUserName": { editable: false, type: "string" }, "isCore": { editable: true, type: "boolean" }, "projTeamId": { editable: false, type: "string" }, "hours": { editable: false, type: "number" }, "empStatus": { editable: false, type: "string" } }}When editing an existing entry in the grid, only empRole and isCore should be editable.
When adding a new entry to the grid, only empLastName, empFirstName, empRole, and isCore should be editable.
The rest should appear as either standard text or greyed-out checkboxes. I am aware that I can simply make all fields inputs and the plugin will automatically filter out which fields accept input and which do not upon submission, but that is undesirable behaviour. We wish to make it visually clear that certain fields are not editable, while being able to have different fields be editable in different scenarios (Add vs Edit).
Is this possible? We really need to find a way to make it possible if it isn't.
Here's the editor template we have so far:
<script id="teamEditorTemplate" type="text/x-kendo-template"> <table> <colgroup> <col width="160" /> <col width="100" /> <col /> </colgroup> <tr> <td rowspan="12"><img class="teamImage" width="128" height="128" data-src="/Content/images/anonymousUser.jpg" src="# if(empUserName === "null") { #/Content/images/anonymousUser.jpg# } else { #@System.Configuration.ConfigurationManager.AppSettings["EmployeePhoto"]#= empUserName #.jpg# } #" /></td> <td><div class="k-edit-label"> <label for="Id">Employee ID:</label> </div></td> <td>#= empId #</td> </tr> <tr> <td><div class="k-edit-label"> <label for="FirstName">First Name:</label> </div></td> <td>#= empFirstName #</td> </tr> <tr> <td><div class="k-edit-label"> <label for="LastName">Last Name:</label> </div></td> <td>#= empLastName #</td> </tr> <tr> <td><div class="k-edit-label"> <label for="Role">Role:</label> </div></td> <td><input type="text" id="Role" class="k-input k-textbox" data-bind="value:empRole" data-value-field="empRole" data-text-field="empRole" data-source="empRoleDropDownDataSource" data-role="dropdownlist" /></td> </tr> <tr> <td><div class="k-edit-label"> <label for="Core">Core Member:</label> </div></td> <td><input type="checkbox" id="Core" class="k-input k-checkbox" data-bind="value:isCore" /></td> </tr> <tr> <td><div class="k-edit-label"> <label for="Active">Active Employee:</label> </div></td> <td><input id="Active" disabled # if(empStatus !== "T") { #checked="checked"# } # type="checkbox" class="k-input k-checkbox" /></td> </tr> <tr> <td><div class="k-edit-label"> <label for="Hours">Hours:</label> </div></td> <td>#= hours #</td> </tr> </table></script>Here's our DataSource declaration:
var dataTeamRead = "/ProjectInfo/GetProjectTeam";var dataTeamUpdate = "/ProjectInfo/UpdateProjectTeam";var dataTeamDestroy = "/ProjectInfo/DestroyProjectTeam";var dataTeamCreate = "/ProjectInfo/CreateProjectTeam";var dataTeam = new kendo.data.DataSource({ pageSize: 10, transport: { read: { url: dataTeamRead, data: { projectId: Querystring.Get("projectId") }, type: "POST", dataType: "json" }, update: { url: dataTeamUpdate, type: "POST", dataType: "json" }, destroy: { url: dataTeamDestroy, type: "POST", dataType: "json" }, create: { url: dataTeamCreate, type: "POST", dataType: "json" } }, schema: { type: "json", model: { id: "empId", fields: { "empId": { editable: false, type: "string" }, "empLastName": { editable: false, type: "string" }, "empFirstName": { editable: false, type: "string" }, "empRole": { editable: true, type: "string" }, "empUserName": { editable: false, type: "string" }, "isCore": { editable: true, type: "boolean" }, "projTeamId": { editable: false, type: "string" }, "hours": { editable: false, type: "number" }, "empStatus": { editable: false, type: "string" } } } }});Here's our kendoGrid declaration:
var kendoGridPageable = { pageSize: 10, previousNext: true, numeric: false, info: true},kendoGridToolbar = [ { name: "create", text: "Add" }, { name: "edit", text: "Edit" }, { name: "destroy", text: "Remove" }];$("#gridTeam").kendoGrid({ rowTemplate: kendo.template($("#teamRowTemplate").html()), columns: [ { "title": " ", "filterable": false, "width": "48px" }, { "field": "empLastName", "title": "Last", "filterable": true, "width": "25%" }, { "field": "empFirstName", "title": "First", "filterable": true, "width": "25%" }, { "field": "empRole", "title": "Role", "filterable": true, "width": "25%" }, { "field": "hours", "title": "Hours", "filterable": true, "width": "25%" } ], dataSource: dataTeam, scrollable: false, sortable: { mode: "multiple", allowUnsort: true }, filterable: true, pageable: kendoGridPageable, selectable: "row", nagivatable: true, toolbar: kendoGridToolbar, editable: { mode: "popup", template: $("#teamEditorTemplate").html(), update: true, destroy: true, confirmation: "Are you sure you want to remove this team member?" }, columnMenu: true});Here's our rowTemplate:
<script id="teamRowTemplate" type="text/x-kendo-template"> <tr class="# if(isCore === true) { #coreMember# } # # if(empStatus === "T") { #terminatedEmployee# } #" data-uid="${uid}"> <td><img class="teamImage" width="32" height="32" data-src="/Content/images/anonymousUser.jpg" src="# if(empUserName === "null") { #/Content/images/anonymousUser.jpg# } else { #@System.Configuration.ConfigurationManager.AppSettings["EmployeePhoto"]#= empUserName #.jpg# } #" /></td> <td>#= empLastName #</td> <td>#= empFirstName #</td> <td>#= empRole #</td> <td>#= hours #</td> </tr></script>Any assistance that can be provided would be most appreciated.
Thank you for your time and screen space. :)