jqGrid가 있고 새 행을 추가 할 때 하나의 열에 기본값이 있어야합니다. 나는 문서화를 따랐지만 그 가치는 결코 나타나지 않는다.jqGrid 기본값이 작동하지 않습니까?
{name: 'Lt', index: 'Lt', width: 25, editable: true, editoptions: {defaultValue: 'N'}}
그리고 이것은 내가 전화하는 방법입니다 addRowData :
이것은 colModel에서 열은
$("#grid").addRowData(-1,
{ Datum: $.datepicker.formatDate("yy-mm-dd", new Date()) }, "first", true)
지금까지 내가, 내가 책에서 그것을하고 있어요 볼 수 있습니다!
전체 그리드의 정의 :
$("#dagbok_grid").jqGrid({
datatype: 'json',
mtype: 'GET',
colNames: [
'a',
'b',
'c',
'd',
'e',
'f',
'g',
'h',
'i',
'j',
'k',
'l',
'm',
'n',
'o',
'p',
'q',
'r',
's'],
colModel: [
{ name: 'a', index: 'a', width: 30, formatter: 'checkbox', edittype: 'checkbox', editable: true },
{ name: 'b', index: 'b', width: 30, formatter: 'checkbox', edittype: 'checkbox', editable: true },
{ name: 'c', index: 'c', width: 70, formatter: 'date', editable: true, editrules: { required: true }, editoptions: { dataInit: function (elem) { $(elem).datepicker(); } } },
{ name: 'd', index: 'd', width: 65, editable: true, formatter: 'date', formatoptions: { srcformat: 'H:i:s', newformat: 'ShortTime' }, editrules: { time: true} },
{ name: 'e', index: 'e', width: 80, edittype: 'select', editable: true, formatter: 'select' },
{ name: 'f', index: 'f', width: 100, editable: true, edittype: 'textarea', editoptions: {rows: '7'} },
{ name: 'g', index: 'g', width: 80, editable: true, edittype: 'textarea', editoptions: { rows: '7'} },
{ name: 'h', index: 'h', width: 80, editable: true, editrules: { maxValue: 50} },
{ name: 'i', index: 'i', width: 120, edittype: 'select', editable: true, formatter: 'select' },
{ name: 'j', index: 'j', width: 200, edittype: 'select', editable: true, formatter: 'select' },
{ name: 'k', index: 'k', width: 70, edittype: 'select', editable: true, formatter: 'select' },
{ name: 'l', index: 'l', width: 70, editable: true, editrules: { maxValue: 10} },
{ name: 'm', index: 'm', width: 25, editable: true, editoptions: { defaultValue: 'N'} },
{ name: 'n', index: 'n', width: 70, editable: true, editrules: { integer: true, maxValue: 999999 }, formatter: formatPosition, unformat: unformatPosition },
{ name: 'o', index: 'o', width: 25, editable: true, editrules: { custom: true, custom_func: chkLongitudTecken} },
{ name: 'p', index: 'p', width: 80, editable: true, editrules: { integer: true, maxValue: 999999 }, formatter: formatPosition, unformat: unformatPosition },
{ name: 'q', index: 'q', width: 80, edittype: 'select', editable: true, formatter: 'select' },
{ name: 'r', index: 'r', width: 100, editable: true, editrules: { maxValue: 50} },
{ name: 's', index: 's', width: 65, edittype: 'select', editable: true, formatter: 'select' },
],
sortname: 'c',
sortorder: 'desc',
shrinkToFit: false,
viewrecords: true,
gridview: true,
onSelectRow: function (id) {
if (id && id !== lastsel) {
jQuery('#dagbok_grid').saveRow(lastsel);
lastsel = id;
}
jQuery('#dagbok_grid').editRow(id, true);
},
height: 400,
editurl: '@Url.Action("SaveGridRow")',
caption: 'my grid'
});
나는 또한 나중에 일부 COLS로 선택-값을 추가 :
$.ajax({
type: 'GET',
url: '@Url.Action("GetGridComboValues")',
async: false,
success: function (data) {
var grid = $("#dagbok_grid");
grid.setColProp("e", { editoptions: { value: data.kallor} });
grid.setColProp("i", { editoptions: { value: data.rubriker} });
grid.setColProp("j", { editoptions: { value: data.verksamheter} });
grid.setColProp("k", { editoptions: { value: data.opPadrag, dataEvents: [{ type: 'change', fn: function (e) {
$.ajax({
type: "GET",
url: '@Url.Action("GetVerksamhetskod")',
data: { "opPadragId": e.currentTarget.value },
dataType: 'json',
success: function (data) {
var selr = jQuery('#dagbok_grid').jqGrid('getGridParam', 'selrow');
jQuery("#dagbok_grid").jqGrid('setCell', selr, "l", data);
}
});
}
}]
}
});
grid.setColProp("q", { editoptions: { value: data.medier} });
grid.setColProp("s", { editoptions: { value: data.regioner} });
}
});
코드 추가 및 삭제는
$("#toolbarAddButton")
.button()
.click(function() {
$("#dagbok_grid").addRowData(-1, { Datum: $.datepicker.formatDate("yy-mm-dd", new Date()) }, "first", true)
});
$("#toolbarDeleteButton").click(function() {
var radid = $("#dagbok_grid").jqGrid("getGridParam", "selrow");
if (radid != null) {
var su = $("#dagbok_grid").jqGrid("delRowData", radid);
$("#dagbok_grid").jqGrid("delGridRow", radid, { url: '@Url.Action("DeleteGridRow")', reloadaftersubmit: false });
}
})
저장되면 사용자에게 실행 편집 모드에서 엔터를 누릅니다.
감사합니다. addRowData가 아닌 경우 행 추가를 위해 어떤 방법을 권장합니까? -1의 목적은 서버 측에 새로 추가 된 행이라는 것을 알고 있다는 것입니다. 나는 그 대신에 어떤 깃발을 사용할 수 있을지도 모른다. 새 행을 추가 할 때만 기본값이 필요하며 이미 기존 행을 채울 때는 필요하지 않습니다. – kaze
@kaze : 당신에게 당신이 행을 추가 할 필요가있는 (자바 스크립트 코드) 및 ** 시나리오 **를 사용하는 그리드에 대한 자세한 정보가 필요 addRowData''의 사용에 대한 최선의 권장 사항을 얻을 수 있습니다. 대부분'data' 매개 변수는'datatype : 'local ''을 사용할 때 가장 좋은 방법입니다.내가 어떻게 대답을 썼는지'addRowData'를 명시 적으로 호출하면 기본값을 설정하는 문제를 이해할 수 없습니다. 왜 단지'Lt : 'N ''을'addRowData'에 의해 추가 된 행의 속성 목록에 추가하지 않습니까? – Oleg
editUrl과 함께 rowEditing을 사용하고 있습니다. 저장을 위해 서버에 업데이트를 보냅니다. 나는 또한 ID를 서버의 delete 메소드로 보내는 delete를 가지고있다. 사용자가 툴바에서 "새"버튼을 누르면 사용자가 값을 입력 할 수 있도록 맨 위에 새 행을 삽입하고 싶습니다. 내 질문을 acutal 코드로 업데이트합니다. – kaze