jqgrid に新しいデータを追加しています。データは顧客に関連しているため、新しいレコードには顧客 ID が含まれている必要があります。したがって、レコードを追加するためのポップアップフォームには、事前に入力された顧客コード (読み取り専用) が必要です。顧客コードはドロップダウン リストで利用できます。私は次のことを試しました - カスタム関数 AddRow でカスタムボタンを追加しました (これは Internet から借用したコードです)。関数内では、setColProp を使用して CustomerId をフィールドに設定しています。しかし、何も起こりません。ポップアップすら表示されません。同じことを行う簡単な方法はありますか?
jQuery("#list").jqGrid({
url: '<%= ResolveClientUrl("~/service/OfficeData.asmx/GetDealer_SMS") %>',
editurl: '<%= ResolveClientUrl("~/service/OfficeData.asmx/InsertDealer_SMS") %>',
datatype: "json",
mtype: 'POST',
ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
ajaxEditOptions: { ContentType: 'application/json; charset=utf-8', dataType: 'json' },
serializeGridData: function (postData) {
//alert("Call");
if (postData.DealerCode === undefined) { postData.DealerCode = DealerCode; }
else {
postData.DealerCode = DealerCode;
}
return JSON.stringify(postData);
},
jsonReader: { repeatitems: false, root: "d.rows", page: "d.page", total: "d.total", records: "d.records" },
colNames: ['ID', 'DealerCode', 'Name', 'Designation', 'Address', 'EMail', 'Mobile'],
colModel: [{ name: 'id', index: 'id', width: 10, align: 'left', editable: true, hidden: true,
editrules: { required: false },
editoptions: {
dataInit: function (element) {
$(element).attr("readonly", "readonly");
}
}
},
{ name: 'DealerCode', index: 'DealerCode', width: 60, align: 'left', editable: true,
editrules: { required: true },
editoptions: {
dataInit: function (element) {
$(element).attr("readonly", "readonly");
}
}
},
{ name: 'RecpName', index: 'RecpName', width: 150, align: 'left', editable: true,
editrules: { required: true }, editoptions: { size: 30, maxlength: 150 }
},
{ name: 'RecpDesignation', index: 'RecpDesignation', width: 100, align: 'left', editable: true,
editrules: { required: true }, editoptions: { size: 30, maxlength: 150 }
},
{ name: 'RecpAddress', index: 'RecpAddress', width: 250, align: 'left', editable: true,
editrules: { required: true }, editoptions: { size: 30, maxlength: 400 }
},
{ name: 'RecpEMail', index: 'RecpEMail', width: 150, align: 'left', editable: true,
editrules: { required: true }, editoptions: { size: 30, maxlength: 150 }
},
{ name: 'RecpMobile', index: 'RecpMobile', width: 100, align: 'left', editable: true,
editrules: { required: true }, editoptions: { size: 30, maxlength: 30 }
}],
loadError: function (jqXHR, textStatus, errorThrown) {
alert('Error while loading -' + errorThrown);
},
pager: jQuery('#pager'),
rowNum: 20,
rowList: [10, 20, 50],
sortname: 'RecpName',
sortorder: "asc",
viewrecords: true,
imgpath: '/scripts/themes/steel/images',
caption: 'Dealer Recepient Details'
}).jqGrid('navGrid', '#pager', { edit: false, add: false, del: false, search: false })
.navButtonAdd('#pager',
{ caption: "Add",
buttonicon: "ui-icon-plus",
onClickButton: addRow,
title: "",
cursor: "pointer"
}
)
.navButtonAdd('#pager',
{ caption: "Edit",
buttonicon: "ui-icon-pencil",
onClickButton: editRow,
position: "last",
title: "",
cursor: "pointer"
}
).navButtonAdd('#pager',
{ caption: "Delete",
buttonicon: "ui-icon-trash",
onClickButton: deleteRow,
position: "last",
title: "",
cursor: "pointer"
}
);
function addRow() {
alert(DealerCode);
$("#grid").jqGrid('setColProp', 'DealerCode', { editoptions: { readonly: true, size: 10, value: DealerCode} });
$('#grid').jqGrid('editGridRow','new',
{ url: '<%= ResolveClientUrl("~/service/OfficeData.asmx/InsertDealer_SMS") %>',
editData: {},
serializeEditData: function(data){
data.id = 0;
return $.param(data);
},
recreateForm: true,
beforeShowForm: function(form) {
$('#pData').hide();
$('#nData').hide();
},
beforeInitData: function(form) {},
closeAfterAdd: true,
reloadAfterSubmit:true,
afterSubmit : function(response, postdata)
{
var result = eval('(' + response.responseText + ')');
var errors = "";
if (result.success == false) {
for (var i = 0; i < result.message.length; i++) {
errors += result.message[i] + "<br/>";
}
} else {
$('#msgbox').text('Entry has been added successfully');
$('#msgbox').dialog(
{ title: 'Success',
modal: true,
buttons: {"Ok": function() {
$(this).dialog("close");}
}
});
}
// only used for adding new records
var newId = null;
return [result.success, errors, newId];
}
});
} // end of addRow
前もって感謝します