【问题标题】:extjs: Grid Buffered Scrolling with Row Editing/Deletion/Additionextjs:带有行编辑/删除/添加的网格缓冲滚动
【发布时间】:2014-02-03 13:56:33
【问题描述】:

有没有人见过任何带有缓冲滚动的 extjs 网格示例,支持新行、行编辑和行删除?

CellEditing 和 RowEditing 插件可以与缓冲滚动一起使用吗?

是否可以使用缓冲滚动进行行编辑?

干杯,

Avi

【问题讨论】:

    标签: extjs grid


    【解决方案1】:

    我在 Ext 论坛上打开了一个帖子并得到响应,插入和删除 支持缓冲滚动。

    http://forums.ext.net/showthread.php?27969-Buffered-Scrolling-with-Row-Editing-Deletion-Addition&p=124559&posted=1#post124559

    干杯,

    视频

    【讨论】:

      【解决方案2】:

      我更改了此示例http://docs.sencha.com/extjs/4.2.2/#!/example/grid/infinite-scroll.html,添加了行编辑器。打开此示例:http://jsfiddle.net/zAnZg/1/,单击记录,更改值,然后单击“更新”

      Ext.require([
          'Ext.grid.*',
          'Ext.data.*',
          'Ext.util.*',
          'Ext.grid.plugin.BufferedRenderer'
      ]);
      
      
      Ext.onReady(function(){
          Ext.define('ForumThread', {
              extend: 'Ext.data.Model',
              fields: [
                  'title', 'forumtitle', 'forumid', 'username', {
                      name: 'replycount',
                      type: 'int'
                  }, {
                      name: 'lastpost',
                      mapping: 'lastpost',
                      type: 'date',
                      dateFormat: 'timestamp'
                  },
                  'lastposter', 'excerpt', 'threadid'
              ],
              idProperty: 'threadid'
          });
      
          // create the Data Store
          var store = Ext.create('Ext.data.Store', {
              id: 'store',
              model: 'ForumThread',
              remoteGroup: true,
              // allow the grid to interact with the paging scroller by buffering
              buffered: true,
              leadingBufferZone: 300,
              pageSize: 100,
              proxy: {
                  // load using script tags for cross domain, if the data in on the same domain as
                  // this page, an Ajax proxy would be better
                  type: 'jsonp',
                  url: 'http://www.sencha.com/forum/remote_topics/index.php',
                  reader: {
                      root: 'topics',
                      totalProperty: 'totalCount'
                  },
                  // sends single sort as multi parameter
                  simpleSortMode: true,
                  // sends single group as multi parameter
                  simpleGroupMode: true,
      
                  // This particular service cannot sort on more than one field, so grouping === sorting.
                  groupParam: 'sort',
                  groupDirectionParam: 'dir'
              },
              sorters: [{
                  property: 'threadid',
                  direction: 'ASC'
              }],
              autoLoad: true,
              listeners: {
      
                  // This particular service cannot sort on more than one field, so if grouped, disable sorting
                  groupchange: function(store, groupers) {
                      var sortable = !store.isGrouped(),
                          headers = grid.headerCt.getVisibleGridColumns(),
                          i, len = headers.length;
      
                      for (i = 0; i < len; i++) {
                          headers[i].sortable = (headers[i].sortable !== undefined) ? headers[i].sortable : sortable;
                      }
                  },
      
                  // This particular service cannot sort on more than one field, so if grouped, disable sorting
                  beforeprefetch: function(store, operation) {
                      if (operation.groupers && operation.groupers.length) {
                          delete operation.sorters;
                      }
                  }
              }
          });
      
          function renderTopic(value, p, record) {
              return Ext.String.format(
                  '<a href="http://sencha.com/forum/showthread.php?t={2}" target="_blank">{0}</a>',
                  value,
                  record.data.forumtitle,
                  record.getId(),
                  record.data.forumid
              );
          }
      
          var rowEditing = Ext.create('Ext.grid.plugin.RowEditing', {
              clicksToMoveEditor: 1,
              clicksToEdit: 1,
              autoCancel: false,
              listeners:{
                  edit: function(editor, e){
                      Ext.MessageBox.alert(
                          'Just create Ajax recuest here. Post changed record:<br/>' +
                          Ext.JSON.encode(e.record.data)
                      );
                  }
              }
          });    
      
          var grid = Ext.create('Ext.grid.Panel', {
              width: 700,
              height: 500,
              collapsible: true,
              title: 'ExtJS.com - Browse Forums',
              store: store,
              loadMask: true,
              selModel: {
                  pruneRemoved: false
              },
              multiSelect: true,
              viewConfig: {
                  trackOver: false
              },
              features:[{
                  ftype: 'grouping',
                  hideGroupedHeader: false
              }],
              plugins: [rowEditing],
              // grid columns
              columns:[{
                  xtype: 'rownumberer',
                  width: 50,
                  sortable: false
              },{
                  tdCls: 'x-grid-cell-topic',
                  text: "Topic",
                  dataIndex: 'title',
                  flex: 1,
                  renderer: renderTopic,
                  sortable: true,
                  editor: {
                      allowBlank: false
                  }
              },{
                  text: "Author",
                  dataIndex: 'username',
                  width: 100,
                  hidden: true,
                  sortable: true
              },{
                  text: "Replies",
                  dataIndex: 'replycount',
                  align: 'center',
                  width: 70,
                  sortable: false,
                  editor: {
                      xtype: 'numberfield',
                      allowBlank: false,
                      minValue: 1,
                      maxValue: 150000
                  }
              },{
                  id: 'last',
                  text: "Last Post",
                  dataIndex: 'lastpost',
                  width: 130,
                  renderer: Ext.util.Format.dateRenderer('n/j/Y g:i A'),
                  sortable: true,
                  groupable: false,
                  editor: {
                      xtype: 'datefield',
                      allowBlank: false,
                      format: 'm/d/Y',
                      minValue: '01/01/2006',
                      minText: 'Cannot have a start date before the company existed!',
                      maxValue: Ext.Date.format(new Date(), 'm/d/Y')
                  }
              }],
              renderTo: Ext.getBody()
          });
      });
      

      【讨论】:

      • 我的编辑工作正常,但插入新记录没有运气,无论我调用什么方法(插入/添加),它都不会添加到存储中。
      • 缓冲存储不支持插入操作。看这里:stackoverflow.com/a/19913300/820436 当我们尝试插入新记录来存储时,我们得到错误:'对象没有方法 filterBy'。但是您可以使用表单创建弹出 ext 窗口以插入新记录
      猜你喜欢
      • 2013-05-08
      • 2014-09-25
      • 2014-07-23
      • 1970-01-01
      • 2015-07-24
      • 2014-02-04
      • 1970-01-01
      • 2011-11-07
      • 2016-06-22
      相关资源
      最近更新 更多