我有一个预先填充公司LAN IP地址的表,其中包含相关数据,状态等字段.(jquery-)jtable字段集合配置如下.
fields: {
id: { title: 'ID'},
ip: { title: 'IP address, edit: false }
more: { ... }
}
Run Code Online (Sandbox Code Playgroud)
这有效但问题是当弹出编辑对话框时,用户无法看到正在编辑的记录的IP地址,因为jtable的编辑表单不显示该字段.
我已经阅读了文档,但看不到任何方式在编辑表单中将字段显示为只读.有任何想法吗?
我不得不破解 jtable.js。从第 2427 行左右开始。更改的行标有“*”。
//Do not create element for non-editable fields
if (field.edit == false) {
//Label hack part 1: Unless 'hidden' we want to show fields even though they can't be edited. Disable the 'continue'.
* //continue;
}
//Hidden field
if (field.type == 'hidden') {
$editForm.append(self._createInputForHidden(fieldName, fieldValue));
continue;
}
//Create a container div for this input field and add to form
var $fieldContainer = $('<div class="jtable-input-field-container"></div>').appendTo($editForm);
//Create a label for input
$fieldContainer.append(self._createInputLabelForRecordField(fieldName));
//Label hack part 2: Create a label containing the field value.
* if (field.edit == false) {
* $fieldContainer.append(self._myCreateLabelWithText(fieldValue));
* continue; //Label hack: Unless 'hidden' we want to show fields even though they can't be edited.
* }
//Create input element with it's current value
Run Code Online (Sandbox Code Playgroud)
在 _createInputLabelForRecordField 之后添加此函数(大约第 1430 行):
/* Hack part 3: Creates label containing non-editable field value.
*************************************************************************/
_myCreateLabelWithText: function (txt) {
return $('<div />')
.addClass('jtable-input-label')
.html(txt);
},
Run Code Online (Sandbox Code Playgroud)
对于 Metro 主题,字段名称和值都将为灰色。
请小心您传回的更新脚本。//edit: false// 字段不会传回任何值,因此请勿将它们包含在更新查询中。