Javascript 如何在 jqgrid 中以编辑形式显示只读字段或以其他方式显示只读列中的整个文本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7056628/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 00:38:50  来源:igfitidea点击:

how to show readonly fields in edit form in jqgrid or other way to show whole text from readonly column

javascriptjqgrid

提问by Andrus

jqGrid colModel contains read-only multi line column defined using properties below. Content line lenghts are greater than column width, text is to long so that tooltio does not show its whole content. It is not possible to see whole content.

jqGrid colModel 包含使用以下属性定义的只读多行列。内容行的长度大于列的宽度,文本太长以至于 tooltio 不会显示其全部内容。不可能看到全部内容。

I'm looking for a way allow user to see whole column content. For example, if edit form button is pressed, this column content should de displayeid in edit form as readonly textarea. However, readonly columns does not appear in edit form.

我正在寻找一种允许用户查看整个列内容的方法。例如,如果编辑表单按钮被按下,则该列内容应该在编辑表单中显示为只读文本区域。但是,只读列不会以编辑形式出现。

How to allow user to see whole column content ?

如何让用户看到整列内容?

colModel: [{
"name":"LoggedLongText",
"editable":false,"width":539,
"classes":"jqgrid-readonlycolumn","fixed":true,
"hidden":false,"searchoptions":{"sopt":["cn","eq","ne","lt","le","gt","ge","bw","ew","nc"]}}
}]

回答by Oleg

Is the setting

是设置

editable: true, editoptions: { readonly: "readonly" }

probably what you need?

可能你需要什么?

UPDATED:Free jqGridsupports more values for editableproperty starting with version 4.8. The wiki articledescribed that editablecan be function and it supports additionally three string values in case of using form editing: "hidden", "disabled"and "readonly".

更新:从 4.8 版开始,免费的 jqGrid支持更多的editable属性值。wiki 文章描述了editable可以是函数,并且在使用表单编辑的情况下它还支持另外三个字符串值:"hidden","disabled""readonly".

回答by jquerybug

To show readonly fields you might try using the "disabled:disabled"inside editoptions.

要显示只读字段,您可以尝试使用"disabled:disabled"inside editoptions

Yet another option is to use a custom element type that returns a span as below:

另一种选择是使用自定义元素类型,返回一个跨度如下:

colModel: [ 
      ... 
      {name:'price', ..., editable:true, edittype:'custom', editoptions:{custom_element: myelem, custom_value:myvalue} },
      ...
   ]
..
function myelem (value, options) {
  var el = document.createElement("span");
  $(el).val(value);    // be sure to escape special characters as necessary.
  return el;
}

function myvalue(elem, operation, value) {
// just reutrun null or empty string.
return "";
}

I prefer this over using "readonly:readonly", because the readonlyoption wraps an input control around the cell value, the input control still receives focus, which I think is misleading to the user. Using "disabled:disabled"keeps the input element from receiving better, which is slightly better, in terms of usability.

我更喜欢使用“ readonly:readonly”,因为该readonly选项在单元格值周围包裹了一个输入控件,输入控件仍然接收焦点,我认为这会误导用户。使用"disabled:disabled"可以防止输入元素更好地接收,这在可用性方面稍微好一些。

Using a span is much better. Interestingly, jqGrid sends even "unsuccessful" form controls to the server.

使用跨度要好得多。有趣的是,jqGrid 甚至将“不成功”的表单控件发送到服务器。

Hope this helps. -- jqr

希望这可以帮助。-- jqr

回答by Nitin Chhabra

To show readonly fields on EditForm, you must try using the {readonly: true}property inside editoptions for a jqGrid column and will work.

要在 EditForm 上显示只读字段,您必须尝试使用{readonly: true}jqGrid 列的 editoptions 内的属性,并且会起作用。