2013-05-28 77 views
1

我正在使用w2uihttp://w2ui.com/)插件。修改w2ui插件

考虑这个例子:1

  1. 我想,当点击添加按钮是一个空行的编辑将出现在网格中添加一个新行?

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

  3. 如何将一列设置为ID?目前它只是识别recid

回答

1

下面是一个简单的单击按钮时如何在网格中添加新的记录:

<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> 

1
  1. 由于这是一个更大的问题。我会在下一篇文章中回答。

  2. 要隐藏搜索框,可以通过设置w2grid.show.toolbarSearch = false;有关更多信息,请参阅http://w2ui.com/web/docs/w2grid.show

  3. recid是必需的唯一字段。它一定要是。但是,您可能有任何数量的附加列不必是可见的,甚至不能在列数组中具有相应的元素。如果服务器端将id作为唯一列返回,您可以添加事件监听器onLoad并通过记录设置recid作为id。我知道这不是很好,但它会完成工作。改变服务器端返回recid将使它变得非常漂亮。

+0

谢谢你,我希望我们看到的配置在将来的版本中设置ID列。 'id:'用户名' – PHPst