JQGrid - 在编辑表单中显示附加列

2024-05-17

我有一个 JQGrid 表,有 30 多个列。我认为这些列的内联编辑对用户来说并不友好。所以我想在网格模式下显示几列,并仅当用户打开该行的编辑表单时显示所有列。这可能吗?在教程中找不到这个。

先感谢您!


如果你想show并且不要编辑列,然后使用视图网格行 http://www.trirand.com/jqgridwiki/doku.php?id=wiki:form_editing#viewgridrow作为使用编辑网格行 http://www.trirand.com/jqgridwiki/doku.php?id=wiki:form_editing#editgridrow。此外,我建议您考虑使用列选择器 http://www.trirand.com/jqgridwiki/doku.php?id=wiki:jquery_ui_methods#column_chooser它允许用户隐藏/显示网格的列或更改其顺序。例如,您可以在网格中仅显示 30 行的子集,使用navGrid http://www.trirand.com/jqgridwiki/doku.php?id=wiki:navigator#definition添加查看详细信息按钮(您需要使用view: true选项)并使用导航按钮添加 http://www.trirand.com/jqgridwiki/doku.php?id=wiki:custom_buttons添加带有列选择器的自定义按钮。您还可以显式调用viewGridRow代替ondblClickRow打回来。需要添加属性editrules: {edithidden: true}在所有需要在查看/编辑/添加表单中可见/可编辑的隐藏列的定义中

生成的网格可能看起来像下面的演示 http://www.ok-soft-gmbh.com/jqGrid/simpleNavGridWithViewAndColumnChooser.htm或者像这里一样:

$(function () {
  "use strict";
  var mydata = [
    { id: "10",  invdate: "2007-10-01", name: "test1",  note: "note1",  amount: "200.00", tax: "10.00", closed: true,  ship_via: "TN", total: "210.00" },
    { id: "20",  invdate: "2007-10-02", name: "test2",  note: "note2",  amount: "300.00", tax: "20.00", closed: false, ship_via: "FE", total: "320.00" },
    { id: "30",  invdate: "2007-09-01", name: "test3",  note: "note3",  amount: "400.00", tax: "30.00", closed: false, ship_via: "FE", total: "430.00" },
    { id: "40",  invdate: "2007-10-04", name: "test4",  note: "note4",  amount: "200.00", tax: "10.00", closed: true,  ship_via: "TN", total: "210.00" },
    { id: "50",  invdate: "2007-10-31", name: "test5",  note: "note5",  amount: "300.00", tax: "20.00", closed: false, ship_via: "FE", total: "320.00" },
    { id: "60",  invdate: "2007-09-06", name: "test6",  note: "note6",  amount: "400.00", tax: "30.00", closed: false, ship_via: "FE", total: "430.00" },
    { id: "70",  invdate: "2007-10-04", name: "test7",  note: "note7",  amount: "200.00", tax: "10.00", closed: true,  ship_via: "TN", total: "210.00" },
    { id: "80",  invdate: "2007-10-03", name: "test8",  note: "note8",  amount: "300.00", tax: "20.00", closed: false, ship_via: "FE", total: "320.00" },
    { id: "90",  invdate: "2007-09-01", name: "test9",  note: "note9",  amount: "400.00", tax: "30.00", closed: false, ship_via: "TN", total: "430.00" },
    { id: "100", invdate: "2007-09-08", name: "test10", note: "note10", amount: "500.00", tax: "30.00", closed: true,  ship_via: "TN", total: "530.00" },
    { id: "110", invdate: "2007-09-08", name: "test11", note: "note11", amount: "500.00", tax: "30.00", closed: false, ship_via: "FE", total: "530.00" },
    { id: "120", invdate: "2007-09-10", name: "test12", note: "note12", amount: "500.00", tax: "30.00", closed: false, ship_via: "FE", total: "530.00" }
  ],
      $grid = $("#list"),
      initDateEdit = function (elem) {
        $(elem).datepicker({
          dateFormat: "dd-M-yy",
          autoSize: true,
          changeYear: true,
          changeMonth: true,
          showButtonPanel: true,
          showWeek: true
        });
      },
      initDateSearch = function (elem) {
        var $self = $(this);
        setTimeout(function () {
          $(elem).datepicker({
            dateFormat: "dd-M-yy",
            autoSize: true,
            changeYear: true,
            changeMonth: true,
            showWeek: true,
            showButtonPanel: true,
            onSelect: function () {
              if (this.id.substr(0, 3) === "gs_") {
                // call triggerToolbar only in case of searching toolbar
                setTimeout(function () {
                  $self[0].triggerToolbar();
                }, 100);
              }
            }
          });
        }, 100);
      },
      numberTemplate = {formatter: "number", align: "right", sorttype: "number",
                        editrules: {number: true, required: true},
                        searchoptions: { sopt: ["eq", "ne", "lt", "le", "gt", "ge", "nu", "nn", "in", "ni"] }};

  $grid.jqGrid({
    datatype: "local",
    data: mydata,
    colNames: ["Client", "Date", "Closed", "Shipped via", "Notes", "Tax", "Amount", "Total"],
    colModel: [
      { name: "name", align: "center", editable: true, width: 65, editrules: {required: true} },
      { name: "invdate", width: 80, align: "center", sorttype: "date",
       formatter: "date", formatoptions: { newformat: "d-M-Y" }, editable: true, datefmt: "d-M-Y",
       editoptions: { dataInit: initDateEdit },
       searchoptions: { sopt: ["eq", "ne", "lt", "le", "gt", "ge"], dataInit: initDateSearch } },
      { name: "closed", width: 70, align: "center", editable: true, formatter: "checkbox",
       edittype: "checkbox", editoptions: {value: "Yes:No", defaultValue: "Yes"},
       stype: "select", searchoptions: { sopt: ["eq", "ne"], value: ":Any;true:Yes;false:No" } },
      { name: "ship_via", width: 105, align: "center", editable: true, formatter: "select",
       edittype: "select", editoptions: { value: "FE:FedEx;TN:TNT;IN:Intim", defaultValue: "IN" },
       stype: "select", searchoptions: { sopt: ["eq", "ne"], value: ":Any;FE:FedEx;TN:TNT;IN:IN" } },
      { name: "note", width: 60, sortable: false, editable: true, edittype: "textarea", hidden: true },
      { name: "tax", width: 52, editable: true, template: numberTemplate, hidden: true  },
      { name: "amount", width: 75, editable: true, template: numberTemplate, hidden: true },
      { name: "total", width: 60, template: numberTemplate }
    ],
    cmTemplate: {editable: true, editrules: {edithidden: true}},
    rowNum: 10,
    rowList: [5, 10, 20],
    pager: "#pager",
    gridview: true,
    autoencode: true,
    ignoreCase: true,
    sortname: "name",
    viewrecords: true,
    sortorder: "desc",
    rownumbers: true,
    shrinkToFit: false,
    height: "auto",
    ondblClickRow: function (rowid) {
      $(this).jqGrid("viewGridRow", rowid);
    }
  });
  $.extend($.jgrid.view, {
    caption: "View Record Details",
    recreateForm: true
  });
  $grid.jqGrid("navGrid", "#pager", {add: false, edit: false, del: false, search: false, refresh: false, view: true,
                                     viewtitle: "View details of selected row"
                                    });
  $grid.jqGrid("navButtonAdd", "#pager", {
    caption: "",
    buttonicon: "ui-icon-calculator",
    title: "Choose Columns to display in the grid",
    onClickButton: function () {
      $(this).jqGrid("columnChooser");
    }
  });
});
.ui-jqgrid-hdiv { overflow-y: hidden; }
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.1/themes/redmond/jquery-ui.css"/>
<link rel="stylesheet" type="text/css" href="http://cdnjs.cloudflare.com/ajax/libs/jqgrid/4.6.0/css/ui.jqgrid.css"/>
<link rel="stylesheet" type="text/css" href="http://cdnjs.cloudflare.com/ajax/libs/jqgrid/4.6.0/plugins/ui.multiselect.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.1/jquery-ui.min.js"></script>
<script type="text/javascript" src="http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-4.6.0/plugins/ui.multiselect-fixed.js"></script>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jqgrid/4.6.0/js/i18n/grid.locale-en.js"></script>
<script type="text/javascript">
  $.jgrid.no_legacy_api = true;
  $.jgrid.useJSON = true;
</script>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jqgrid/4.6.0/js/jquery.jqGrid.src.js"></script>
<script type="text/javascript" src="http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-4.6.0/plugins/jQuery.jqGrid.columnChooser.js"></script>

<table id="list"><tr><td></td></tr></table>
<div id="pager"></div>

顺便说一下你可以使用rowpos and colpos的属性表单选项 http://www.trirand.com/jqgridwiki/doku.php?id=wiki%3Acommon_rules#formoptions以多列形式显示添加/编辑/查看表单的信息。看答案 https://stackoverflow.com/a/10852741/315935对应的代码示例。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

JQGrid - 在编辑表单中显示附加列 的相关文章

  • 未捕获的类型错误:无法读取未定义的属性“toLowerCase”

    我收到此错误 它源自 jquery 框架 当我尝试加载准备好的文档上的选择列表时 出现此错误 我似乎无法找到为什么会出现此错误 它适用于更改事件 但在尝试手动执行该函数时出现错误 未捕获的类型错误 无法读取未定义的属性 toLowerCas
  • 如何在 jquery 中使 ajax 数据键动态化?

    我试图使内联编辑成为动态的 因此它只依赖于我的标记中的一些数据属性 所以现在的代码如下 inline edit editable function value settings var editableField this ajax typ
  • 匹配数组中的对象并合并

    UPDATE 我有一个名为的对象数组cars包含 li 标签 其中包含有关汽车的属性数据 例如价格 汽车类型等 我的目标是 如果这些汽车符合某些标准 则将它们合并到一个列表中 要求 快速性能 保持相同的汽车数组结构 Main Goal Ma
  • 使用 jQuery 检查输入是否为空

    我有一个表单 我希望填写所有字段 如果单击某个字段然后未填写 我想显示红色背景 这是我的代码 apply form input blur function if input text is empty this parents p addC
  • 使用 javascript 将 html 文本渲染为位图,无需服务器端代码

    我需要使用 javascript 代码来转换 html 中的文章 帖子 以便最终用户以位图的形式查看 有没有办法在没有服务器端代码的情况下做到这一点 example p testing text here p 您可以使用例如html2can
  • Ajax JSON 数据和灯箱冲突

    我有一个带有灯箱插件的画廊设置光廊 http sachinchoolur github io lightGallery docs 该画廊与静态 HTML 完美配合 当我动态抓取 API 数据并尝试让灯箱处理这些项目时 问题就出现了 我似乎无
  • Javascript 中的线性回归 [关闭]

    Closed 这个问题正在寻求书籍 工具 软件库等的推荐 不满足堆栈溢出指南 help closed questions 目前不接受答案 我想在网络浏览器中用 Javascript 进行最小二乘拟合 目前 用户使用 HTML 文本输入输入数
  • 如何使用JQuery和Django(ajax + HttpResponse)?

    假设我有一个 AJAX 函数 function callpage ajax method get url abc data x 3 beforeSend function success function html IF HTTPRESPO
  • jQuery 检索和设置 html select 元素的选定选项值

    我正在尝试使用 jQuery 检索并设置选择元素 下拉列表 的选定值 为了检索我已经尝试过 myId find selected val 也 myId val 但两者都返回未定义 任何对此问题的见解将不胜感激 要获取 设置选择元素的实际 s
  • 水平平滑滚动 100px

    Heyjo problem 一周以来我一直在寻找 javascript 或 jQuery 代码 以便在我的网站上实现滚动按钮 我失败的那一刻是按钮应该多次工作的时候 他的任务不是滚动到专用元素 而是应该向左滚动 例如 100px 此外 滚动
  • 限制 jQuery id 字符串吗?

    简而言之 我的问题是字符串在 jQuery 中作为可搜索 id 或可搜索内容有什么限制 更新 我得到了 ID 部分 但不是为什么我什至无法使用该字符串搜索 html 内容 对于任何愿意告诉我一个正则表达式来将模式从 MM dd yy HH
  • jqGrid刷新本地数据(JSON对象)

    我正在尝试将 jqGrid 与本地数据一起使用 但发现了几个问题 我正在初始化这样的事情 function refreshGrid grid results grid jqGrid data results datatype local c
  • 如何删除除任何特定 id 之外的元素

    假设有一个父 id 其中包含许多元素 我想删除除一个元素之外的所有元素 ex parent id children not id n remove
  • 使用 AJAX 加载部分视图不起作用

    请原谅我 我是 MVC 和 AJAX 的新手 目前我只是提交一个表单 我想使用表单中的数据使用 ajax 更新部分视图中的表 My UserInfo部分视图如下所示 model IEnumerable
  • Jquery 悬停卡

    我在用着http designwithpc com Plugins Hovercard http designwithpc com Plugins Hovercard 但我不知道如何在悬停卡上声明 var 每个工作描述都有自己的 ID 当悬
  • 如何通过单击链接来更改 div 的内容?

    这是我的网页的 修改后的 jsfiddle 它还有很多 而且定位是正确的 与此相反 http jsfiddle net ry0tec3p 1 http jsfiddle net ry0tec3p 1 a href class btn1 st
  • 编辑第一个选项名称

    我有以下我无法访问的代码 我想要做的是将一些文本添加到现在为空的第一个选项中 诸如 选择地址 之类的文本
  • 覆盖 jQuery 验证 MVC4 中的默认设置

    要覆盖查询验证插件 请在文件 http docs jquery com Plugins Validation validate toptions 推荐的方式是 selector validate invalidHandler functio
  • 滚动顶部不符合预期

    Note 由于上次忘记奖励而重新开放赏金 A Woff 大师已经给出答案 我想在用户展开某一行时到达该行 这样当最后一个可见行展开时 用户不必向下滚动即可查看内容 I used example tbody on click td green
  • 没有输入的 jQuery 日期选择器

    我有一个相当复杂的网络应用程序 我想向其中添加一些日期选择 UI 我遇到的问题是我无法从文档中弄清楚如何真正控制日期选择器的出现方式和时间 不涉及任何表单元素 不 我不会添加秘密表单字段 因此简单的开箱即用方法根本行不通 我希望有人可以提供

随机推荐