基於Bruno's answer我創建了一個動態的jqGrid但直列編輯似乎並不工作:聯編輯不工作動態的jqGrid
var colN = '{ "JSON":"success","colNames":["Id","Name","Check In","Check Out","Check In","Check Out","Check In","Check Out","Check In","Check Out"],';
var colM = '"colModel":[ { "name": "IdEmployee", "index": "IdEmployee", "jsonmap":"IdEmployee", "width": "120", "align": "center", "key": "true", "editable": "false"},{ "name": "NameEmp", "index": "NameEmp", "jsonmap":"NameEmp", "width": "450", "align": "center", "editable": "false"},{ "name": "IDay7", "index": "IDay7", "jsonmap": "IDay7", "width": "170", "align": "center", "editable": "true"},{ "name": "ODay7", "index": "ODay7", "jsonmap": "ODay7", "width": "170", "align": "center", "editable": "true"},{ "name": "IDay8", "index": "IDay8", "jsonmap": "IDay8", "width": "170", "align": "center", "editable": "true"},{ "name": "ODay8", "index": "ODay8", "jsonmap": "ODay8", "width": "170", "align": "center", "editable": "true"},{ "name": "IDay9", "index": "IDay9", "jsonmap": "IDay9", "width": "170", "align": "center", "editable": "true"},{ "name": "ODay9", "index": "ODay9", "jsonmap": "ODay9", "width": "170", "align": "center", "editable": "true"},{ "name": "IDay10", "index": "IDay10", "jsonmap": "IDay10", "width": "170", "align": "center", "editable": "true"},{ "name": "ODay10", "index": "ODay10", "jsonmap": "ODay10", "width": "170", "align": "center", "editable": "true"}],';
var colG = '"gridModel":{ "dataset":[{"IdEmployee":"560","NameEmp":"L A S","IDay9":"07:37:07","ODay9":"20:04:46","IDay10":"20:01:35","ODay10":"07:38:47"},{"IdEmployee":"859","NameEmp":"A P A","IDay7":"19:29:37","ODay7":"08:05:00","IDay8":"19:29:19","ODay8":"08:00:12","IDay9":"19:31:36","ODay9":"08:00:59"},{"IdEmployee":"864","NameEmp":"M R T","IDay8":"07:17:21","ODay8":"20:07:27","IDay9":"07:20:01","ODay9":"20:07:24"}],"page":"1","records":"3","total":"1"}}';
var jsonGrid = jQuery.parseJSON(colN + colM + colG);
var gridPreNomina = $("#tblPreNomina");
gridPreNomina.jqGrid({
jsonReader: {
root: "dataset",
id: "IdEmployee",
page: "page",
total: "total",
records: "records"
},
datatype: 'jsonstring',
datastr: jsonGrid.gridModel,
colNames: jsonGrid.colNames,
colModel: jsonGrid.colModel,
pager: $('#pagerPreNomina'),
rowList: [],
rowNum: '',
loadonce: true,
width: '1200',
height: '100',
viewrecords: true
})
gridPreNomina.jqGrid('inlineNav', "#pagerPreNomina", { add: false, edit: true });
我減少了jqGrid的代碼,並與jsonReader選項,但結果打是相似的。
預先感謝
編輯:我使用的jqGrid免費4.9.2
EDIT2:這使電網的工作方式,改進語法:
$(function() {
"use strict";
var colN = '{ "JSON":"success","colNames":["Id","Name","Check In","Check Out","Check In","Check Out","Check In","Check Out","Check In","Check Out"],';
var colM = '"colModel":[ { "name": "IdEmployee", "index": "IdEmployee", "jsonmap":"IdEmployee", "width": "120", "align": "center", "key": "true", "editable": "false"},{ "name": "NameEmp", "index": "NameEmp", "jsonmap":"NameEmp", "width": "450", "align": "center", "editable": "false"},{ "name": "IDay7", "index": "IDay7", "jsonmap": "IDay7", "width": "170", "align": "center"},{ "name": "ODay7", "index": "ODay7", "jsonmap": "ODay7", "width": "170", "align": "center"},{ "name": "IDay8", "index": "IDay8", "jsonmap": "IDay8", "width": "170", "align": "center"},{ "name": "ODay8", "index": "ODay8", "jsonmap": "ODay8", "width": "170", "align": "center"},{ "name": "IDay9", "index": "IDay9", "jsonmap": "IDay9", "width": "170", "align": "center"},{ "name": "ODay9", "index": "ODay9", "jsonmap": "ODay9", "width": "170", "align": "center"},{ "name": "IDay10", "index": "IDay10", "jsonmap": "IDay10", "width": "170", "align": "center"},{ "name": "ODay10", "index": "ODay10", "jsonmap": "ODay10", "width": "170", "align": "center"}],';
var colG = '"gridModel":{ "dataset":[{"IdEmployee":"560","NameEmp":"L A S","IDay9":"07:37:07","ODay9":"20:04:46","IDay10":"20:01:35","ODay10":"07:38:47"},{"IdEmployee":"859","NameEmp":"A P A","IDay7":"19:29:37","ODay7":"08:05:00","IDay8":"19:29:19","ODay8":"08:00:12","IDay9":"19:31:36","ODay9":"08:00:59"},{"IdEmployee":"864","NameEmp":"M R T","IDay8":"07:17:21","ODay8":"20:07:27","IDay9":"07:20:01","ODay9":"20:07:24"}],"page":"1","records":"3","total":"1"}}';
var jsonGrid = jQuery.parseJSON(colN + colM + colG);
$("#tblPreNomina").jqGrid({
jsonReader: {
root: "dataset",
id: "IdEmployee"
},
cmTemplate: { editable: true, autoResizable: true },
iconSet: "fontAwesome",
datatype: "jsonstring",
datastr: jsonGrid.gridModel,
colNames: jsonGrid.colNames,
colModel: jsonGrid.colModel,
pager: true,
width: 1200,
height: 100,
viewrecords: true,
navOptions: {add: false, edit: false, del: false, search: false, refresh: false },
inlineNavOptions: { edit: true }
}).jqGrid('inlineNav');
});
感謝您對Oleg的快速響應。不幸的是,包括對「navGrid」的調用仍然不起作用,我嘗試了最新版本,仍然無法正常工作 –
@DarK_WisH:不客氣!請參閱** UPDATED **部分我的答案。我建議您另外更新到最新的免費jqGrid 4.12.1。 – Oleg
你的例子不起作用。但是,如果我刪除所有「可編輯:真」,並保留「cmTemplate」它的作品!再次感謝,也爲我展示了新的免費jqGrid語法! –