사용자가 JQGrid에서 행을 선택하면 편집 가능한 필드를 편집 한 다음 Enter 키를 눌러 데이터베이스를 업데이트 할 컨트롤러 메서드에 행을 게시합니다. 업데이트 된 데이터를 게시하는 방법을 찾을 수 없습니다. businessUnitId 필드와 편집 가능한 필드를 매개 변수로 보내 컨트롤러 메터에 보내고 싶습니다. 이것은 내 웹 페이지입니다.JQGrid - 인라인 편집을 사용하는 방법?
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Maintenance
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<fieldset>
<legend>Maintenance of Departments and Divisions</legend>
<p>Add, edit or delete a department or division: <%: Html.DropDownList("BusinessUnitTypes")%></p>
<p>To amend the department or division, select the row, make the change and then press the return key.</p>
<table id="list" class="scroll"></table>
<div id="pager" class="scroll" style="text-align:center;font-size: 11px;"></div>
</fieldset>
<!-- "BusinessUnitTypeId", (SelectList)ViewData["BusinessUnitTypes"] -->
<script type="text/javascript">
$(document).ready(function() { reloadGrid(); });
$('#BusinessUnitTypes').change(function() {
$("#list").trigger("reloadGrid");
});
function reloadGrid() {
var lastSelectedId;
$('#list').jqGrid({
url: '<%: Url.Action("GetBusinessUnits", "BusinessUnit")%>',
postData: {
businessUnitTypeId: function() { return $("#BusinessUnitTypes option:selected").val(); }
},
datatype: 'json',
mtype: 'POST',
colNames: ['ID', 'Name', 'Fax', 'Email', "Employees"],
colModel: [
{ name: 'BusinessUnitId', index: 'BusinessUnitId', width: 25, editable: false },
{ name: 'BusinessUnitName', index: 'BusinessUnitName', width: 200, editable: true, edittype: 'text' },
{ name: 'Fax', index: 'Fax', width: 80, align: 'right', edittype: 'text', editable: true },
{ name: 'Email', index: 'Email', width: 200, editable: true, edittype: 'text' },
{ name: 'NumberOfEmployees', index: 'NumberOfEmployees', width: 70, editable: false}],
rowNum: 20,
rowList: [10, 20, 30],
pager: $('#pager'),
sortname: 'BusinessUnitName',
viewrecords: true,
sortorder: "asc",
caption: "Edit",
height: 575,
onSelectRow: function (id) {
if (id && id !== lastSelectedId) {
$('#list').restoreRow(lastSelectedId);
$('#list').editRow(id, true);
lastSelectedId = id;
}
},
editurl: '<%: Url.Action("Save", "BusinessUnit")%>'
});
}
</script>
</asp:Content>
설정 키 : true는 id 필드에 올바른 값을 채 웁니다. 고마워요. 당신이 내게 준 다른 팁도 고맙습니다. – arame3333
@ arame3333 : 환영합니다! 'onSelectRow'와 같은 jqGrid 콜백 내에서'$ ('list')'대신'$ (this)'를 사용하는 것이 좋습니다. 코드를 조금만 빠르게 작성할 필요는 없지만 대부분이 코드를 관리하기 쉽게 만듭니다. 다른 프로젝트에서 필요하다면 코드 잘라 내기 및 붙여 넣기를 더 쉽게 사용할 수 있습니다. – Oleg