javascript - 修改 w2ui 插件

标签 javascript jquery plugins w2ui

我正在使用 w2ui( http://w2ui.com/ ) 插件。

考虑这个例子:1

  1. 我希望在单击添加按钮时在网格中出现一个空的可编辑行以添加新行?

  2. 我没有找到隐藏搜索框的配置,如何隐藏它?

  3. 如何将列设置为 id?目前它只能识别recid

最佳答案

以下是单击按钮时如何在网格中添加新记录的示例:

    <html>
    <head>
    <link rel="stylesheet" type="text/css" media="screen" href="../css/w2ui.css" /> 
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script type="text/javascript" src="../js/w2ui.js"></script>
    <script>
    $(function () {
      $('#grid').w2grid({ 
        name: 'grid', 
        show: { 
          toolbar: true,
          footer: true,
          header: true,
          columnHeaders: true,
          lineNumbers: true,
          toolbarDelete: true,
          toolbarSave: true,
          toolbarAdd: true
        },
        columns: [        
          { field: 'recid', caption: 'ID', size: '50px', sortable: true, resizable: true, searchable: 'int' },
          { field: 'lname', caption: 'Last Name', size: '30%', sortable: true, resizable: true, searchable: true,
            editable: { type: 'text' }
          },
          { field: 'fname', caption: 'First Name', size: '30%', sortable: true, resizable: true, searchable: true,
            editable: { type: 'text' }
          },
        ],
        onAdd: function (target, data) {
          var recid = 1;
          if (this.records.length > 0) recid = (Math.max.apply(Math, this.find({}))) + 1;
          this.add({ recid: recid });
          $('#grid_grid_edit_'+ (this.records.length - 1) +'_1').focus();
        },
        onSave: function (target, data) {
          var obj = this;
          console.log(data);
          data.onComplete = function () {
            for (var r in data.changed) {
              obj.get(data.changed[r].recid).editable = false;
            }
            obj.refresh();
          }
        }
      });
    });
    </script>
    </head>
    <body>
      <div id="grid" style="width: 100%; height: 500px;"></div>
    </body>
    </html>

关于javascript - 修改 w2ui 插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16790988/

相关文章:

javascript - 如何迭代 getElementByClassName 返回

javascript - 在 passport.js 中带有 token 的验证电子邮件

javascript - 如何在 Jquery selectize 中找到 EOL(行尾)?

plugins - Cordova 3.0.0 - 如何安装插件

linux - 如何将 Dell Equillogic 添加到 Nagios

java - Bukkit/Spigotplugin - 从配置中删除条目

javascript - 根据 javascript 中的数字/对象对数组或 json 进行排序

javascript - JQuery 点击函数没有被调用

javascript - jquery ui 对话框只打开一次

jquery - HTML5 视频中的加载器在 Safari 中不起作用