com.extjs.gxt.ui.client.widget.grid.Grid类的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(16.9k)|赞(0)|评价(0)|浏览(152)

本文整理了Java中com.extjs.gxt.ui.client.widget.grid.Grid类的一些代码示例,展示了Grid类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Grid类的具体详情如下:
包路径:com.extjs.gxt.ui.client.widget.grid.Grid
类名称:Grid

Grid介绍

[英]This class represents the primary interface of a component based grid control. The grid requires a ListStore and ColumnModel when constructed. Each model in the store will be rendered as a row in the grid. Any updates to the store are automatically pushed to the grid. This includes inserting, removing, sorting and filter.

Grid support several ways to manage column widths.

  1. The most basic approach is to simply give pixel widths to each column. Columns widths will match the specified values.
  2. A column can be set to "fill" all available space. As the width of the grid changes, or columns are resized, the "filling" column's width is adjusted so that the column's fill the available width with no horizontal scrolling. See @link Grid#setAutoExpandColumn(String).
  3. Grid can resize columns based on a "weight". As the width of the grid, or columns change, the "weight" is used to allocate the extra space, or the space needed to be reduced. Use GridView#setAutoFill(boolean) to enable this feature. With auto fill, the calculations are only run once. After the grid is rendered, the columns widths will not be adjusted when available width changes. You can use @link GridView#setForceFit(boolean) to always run the width calculations on any changes to available width or column sizes. Columns can be "fixed" which prevents their columns widths to be adjusted by the grid "weight" calculations. See @link ColumnConfig#setFixed(boolean).

When state is enabled (default is false), Grid will save and restore the column width, column hidden state, sort direction, and sort field. To enable state, see #setStateful(boolean). When the store uses a PagingListLoader the offset and limit parameter are saved with the Grid's state. These 2 values can be retrieved and used to make the first load request to return the user to the same location they left the grid. Code snippet:

PagingLoadConfig config = new BasePagingLoadConfig(); 
config.setOffset(0); 
config.setLimit(50); 
Map state = grid.getState(); 
if (state.containsKey("offset")) { 
int offset = (Integer)state.get("offset"); 
int limit = (Integer)state.get("limit"); 
config.setOffset(offset); 
config.setLimit(limit); 
} 
if (state.containsKey("sortField")) { 
config.setSortField((String)state.get("sortField")); 
config.setSortDir(SortDir.valueOf((String)state.get("sortDir"))); 
} 
loader.load(config);

Events:CellClick : GridEvent(grid, rowIndex, cellIndex, event)

Fires after a cell is clicked.

  • grid : this
  • rowIndex : row index
  • cellIndex : cell index
  • event : the dom event
    CellDoubleClick : GridEvent(grid, rowIndex, cellIndex, event)

Fires after a cell is double clicked.

  • grid : this
  • rowIndex : row index
  • cellIndex : cell index
  • event : the dom event
    CellMouseDown : GridEvent(grid, rowIndex, cellIndex, event)

Fires before a cell is clicked.

  • grid : this
  • rowIndex : row index
  • cellIndex : cell index
  • event : the dom event
    RowClick : GridEvent(grid, rowIndex, cellIndex, event)

Fires after a row is clicked.

  • grid : this
  • rowIndex : the row index
  • cellIndex : cell index
  • index : the cell index
  • event : the dom event
    RowDoubleClick : GridEvent(grid, rowIndex, cellIndex, event)

Fires after a row is double clicked.

  • grid : this
  • rowIndex : the row index
  • index : the cell index
  • event : the dom event
    RowMouseDown : GridEvent(grid, rowIndex, colIndex, event)

Fires before a row is clicked.

  • grid : this
  • rowIndex : row index
  • colIndex : column index
  • event : the dom event
    HeaderClick : GridEvent(grid, rowIndex, colIndex, event)

Fires a header is clicked.

  • grid : this
  • rowIndex : row index
  • colIndex : column index
  • event : the dom event
    HeaderDoubleClick : GridEvent(grid, rowIndex, colIndex, event)

Fires a header is double clicked.

  • grid : this
  • rowIndex : row index
  • colIndex : column index
  • event : the dom event
    HeaderMouseDown : GridEvent(grid, rowIndex, colIndex, event)

Fires before a header is clicked.

  • grid : this
  • rowIndex : row index
  • colIndex : column index
  • event : the dom event
    ContextMenu : GridEvent(grid)

Fires before the grid's context menu is shown. Listeners can cancel the action by calling BaseEvent#setCancelled(boolean).

  • grid : this
    HeaderContextMenu : GridEvent(grid, colIndex, menu)

Fires right before the header's context menu is displayed. Listeners can cancel the action by calling BaseEvent#setCancelled(boolean).

  • grid : this
  • colIndex : the column index
  • menu : the context menu
    BodyScroll : GridEvent(grid, srollLeft, scrollTop)

Fires when the body element is scrolled.

  • grid : this
  • scrollLeft : scrollLeft
  • scrollTop : scrollTop
    ColumnResize : GridEvent(grid, colIndex, width)

Fires when the user resizes a column.

  • grid : this
  • colIndex : the column index
  • width : the new column width
    ColumnMove : GridEvent(grid, colIndex, size)

Fires when the user moves a column.

  • grid : this
  • oldIndex : the old column index
  • newIndex : the new column index
    SortChange : GridEvent(grid, sortInfo)

Fires when the grid's store sort changes.

  • grid : this
  • sortInfo : the sort field and direction
    ViewReady : GridEvent(grid)

Fires when the grid's view is ready.

  • grid : this
    Reconfigure : GridEvent(grid)

Fires when the grid gets reconfigured.

  • grid : this
    Inherited Events: BoxComponent Move BoxComponent Resize Component Enable Component Disable Component BeforeHide Component Hide Component BeforeShow Component Show Component Attach Component Detach Component BeforeRender Component Render Component BrowserEvent Component BeforeStateRestore Component StateRestore Component BeforeStateSave Component SaveState
    [中]此类表示基于组件的网格控件的主接口。构造网格时需要ListStoreColumnModel。存储中的每个模型都将在网格中渲染为一行。对存储的任何更新都会自动推送到网格中。这包括插入、删除、排序和筛选。
    网格支持多种方式来管理列宽。
    1.最基本的方法是简单地为每列指定像素宽度。列宽将与指定的值匹配。
    1.可以将一列设置为“填充”所有可用空间。随着网格宽度的更改,或列的大小调整,“填充”列的宽度将调整,以使列的填充宽度与可用宽度相同,而无需水平滚动。请参见@link Grid#setAutoExpandColumn(字符串)。
    1.网格可以根据“权重”调整列的大小。当网格或列的宽度改变时,“权重”用于分配额外的空间,或需要减少的空间。使用GridView#setAutoFill(布尔值)启用此功能。使用“自动填充”,计算只运行一次。渲染网格后,当可用宽度更改时,列宽将不会调整。您可以使用@link GridView#setForceFit(布尔值)在对可用宽度或列大小进行任何更改时始终运行宽度计算。柱可以是“固定”的,这可以防止通过网格“重量”计算调整柱的宽度。请参阅@link ColumnConfig#setFixed(布尔值)。
    启用状态时(默认值为false),Grid将保存和恢复列宽、列隐藏状态、排序方向和排序字段。要启用状态,请参阅#setStateful(布尔值)。当存储使用PagingListLoader时,偏移量和限制参数与网格状态一起保存。这两个值可以被检索并用于发出第一个加载请求,以将用户返回到他们离开网格的相同位置。代码段:
PagingLoadConfig config = new BasePagingLoadConfig(); 
config.setOffset(0); 
config.setLimit(50); 
Map state = grid.getState(); 
if (state.containsKey("offset")) { 
int offset = (Integer)state.get("offset"); 
int limit = (Integer)state.get("limit"); 
config.setOffset(offset); 
config.setLimit(limit); 
} 
if (state.containsKey("sortField")) { 
config.setSortField((String)state.get("sortField")); 
config.setSortDir(SortDir.valueOf((String)state.get("sortDir"))); 
} 
loader.load(config);

事件:单元格单击:GridEvent(网格、行索引、单元格索引、事件)
单击单元格后激发。
*网格:这个
*行索引:行索引
*单元索引:单元索引
*事件:dom事件
CellDoubleClick:GridEvent(网格、行索引、单元格索引、事件)
双击单元格后激发。
*网格:这个
*行索引:行索引
*单元索引:单元索引
*事件:dom事件
CellMouseDown:GridEvent(网格、行索引、单元格索引、事件)
在单击单元格之前激发。
*网格:这个
*行索引:行索引
*单元索引:单元索引
*事件:dom事件
行单击:GridEvent(网格、行索引、单元格索引、事件)
单击行后激发。
*网格:这个
*行索引:行索引
*单元索引:单元索引
*索引:单元格索引
*事件:dom事件
行双击:GridEvent(网格、行索引、单元格索引、事件)
双击行后激发。
*网格:这个
*行索引:行索引
*索引:单元格索引
*事件:dom事件
RowMouseDown:GridEvent(网格、rowIndex、colIndex、事件)
在单击行之前激发。
*网格:这个
*行索引:行索引
*colIndex:列索引
*事件:dom事件
HeaderClick:GridEvent(网格、行索引、共索引、事件)
单击时激发标题。
*网格:这个
*行索引:行索引
*colIndex:列索引
*事件:dom事件
HeaderDoubleClick:GridEvent(网格、行索引、共索引、事件)
双击时激发标题。
*网格:这个
*行索引:行索引
*colIndex:列索引
*事件:dom事件
HeaderMouseDown:GridEvent(网格、行索引、共索引、事件)
在单击标头之前激发。
*网格:这个
*行索引:行索引
*colIndex:列索引
*事件:dom事件
上下文菜单:GridEvent(网格)
在显示网格的关联菜单之前激发。侦听器可以通过调用BaseEvent#setCancelled(布尔值)来取消操作。
*网格:这个
HeaderContextMenu:GridEvent(网格、colIndex、菜单)
在显示标题的关联菜单之前激发。侦听器可以通过调用BaseEvent#setCancelled(布尔值)来取消操作。
*网格:这个
*colIndex:列索引
*菜单:上下文菜单
BodyScroll:GridEvent(grid、srollLeft、scrollTop)
滚动主体元素时激发。
*网格:这个
*滚动左:滚动左
*滚动顶:滚动顶
ColumnResize:GridEvent(网格、共索引、宽度)
当用户调整列的大小时激发。
*网格:这个
*colIndex:列索引
*宽度:新的列宽
ColumnMove:GridEvent(网格、共索引、大小)
当用户移动列时激发。
*网格:这个
*oldIndex:旧列索引
*newIndex:新的列索引
SortChange:GridEvent(网格,sortInfo)
当网格的存储排序更改时激发。
*网格:这个
*sortInfo:排序字段和方向
ViewReady:GridEvent(网格)
在栅格视图准备就绪时激发。
*网格:这个
重新配置:GridEvent(网格)
重新配置网格时激发。
*网格:这个
继承的事件:BoxComponent Move BoxComponent Resize Component Enable Component Disable Component BeforeHide Component Hide Component BeforeShow Component Show Component Show Component Attach Component Detach Component BeforeRender Component Render Component Browser事件Component BeforeStateRestore Component StateRes储蓄国

代码示例

代码示例来源:origin: bedatadriven/activityinfo

private void createGrid() {
  grid = new Grid<UserDatabaseDTO>(presenter.getStore(), createColumnModel());
  grid.setAutoExpandColumn("fullName");
  grid.setLoadMask(true);
  grid.addListener(Events.RowDoubleClick, new Listener<GridEvent>() {
    @Override
    public void handleEvent(GridEvent be) {
      presenter.onUIAction(UIActions.EDIT);
    }
  });
  grid.getSelectionModel().addSelectionChangedListener(new SelectionChangedListener<UserDatabaseDTO>() {
    @Override
    public void selectionChanged(SelectionChangedEvent<UserDatabaseDTO> se) {
      presenter.onSelectionChanged(se.getSelectedItem());
    }
  });
  add(grid);
}

代码示例来源:origin: com.extjs/gxt

@SuppressWarnings("unchecked")
public void bindGrid(Grid grid) {
 if (this.grid != null) {
  this.grid.removeListener(Events.RowMouseDown, this);
  this.grid.removeListener(Events.RowClick, this);
  this.grid.removeListener(Events.ContextMenu, this);
  this.grid.removeListener(Events.ViewReady, this);
  this.grid.getView().removeListener(Events.RowUpdated, this);
  this.grid.getView().removeListener(Events.Refresh, this);
  this.grid.getColumnModel().removeListener(Events.HiddenChange, this);
  keyNav.bind(null);
  bind(null);
 }
 this.grid = grid;
 if (grid != null) {
  grid.addListener(Events.RowMouseDown, this);
  grid.addListener(Events.RowClick, this);
  grid.addListener(Events.ContextMenu, this);
  grid.addListener(Events.ViewReady, this);
  grid.getView().addListener(Events.RowUpdated, this);
  grid.getView().addListener(Events.Refresh, this);
  grid.getColumnModel().addListener(Events.HiddenChange, this);
  keyNav.bind(grid);
  bind(grid.getStore());
  grouped = grid.getView() instanceof GroupingView;
  if (grouped) groupingView = (GroupingView) grid.getView();
 }
}

代码示例来源:origin: geoserver/geofence

/**
 * Inits the grid.
 */
private void initGrid() {
  ColumnModel cm = prepareColumnModel();
  grid = new Grid<T>(store, cm);
  grid.setBorders(true);
  grid.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
 
  grid.setHeight("95%");
  grid.setLazyRowRender(0);
  setGridProperties();
}

代码示例来源:origin: com.extjs/gxt

@SuppressWarnings({"unchecked", "rawtypes"})
public void bind(Grid grid) {
 this.grid = grid;
 this.store = grid.getStore();
 this.cm = grid.getColumnModel();
}

代码示例来源:origin: geoserver/geofence

@Override
public void setGridProperties()
{
  grid.setLoadMask(true);
  grid.setAutoWidth(true);
}

代码示例来源:origin: geoserver/geofence

@Override
public void setGridProperties()
{
  grid.setLoadMask(true);
  grid.setAutoWidth(true);
  //grid.setHeight(300);
  grid.setAutoHeight(true);
  grid.setAutoWidth(true);
}

代码示例来源:origin: geoserver/geofence

/**
 * Inits the grid.
 */
private void initGrid() {
  ColumnModel cm = prepareColumnModel();
  grid = new Grid<T>(store, cm);
  grid.setBorders(true);
  grid.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
  grid.setAutoWidth(true);
  grid.setLoadMask(true);
  grid.setLazyRowRender(0);
  setGridProperties();
}

代码示例来源:origin: geoserver/geofence

/**
 * Inits the grid.
 */
private void initGrid() {
  ColumnModel cm = prepareColumnModel();
  grid = new Grid<T>(store, cm);
  grid.setBorders(true);
  grid.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
  grid.addListener(Events.CellClick, new Listener<BaseEvent>() {
    public void handleEvent(BaseEvent be) {
      if (!grid.getSelectionModel().getSelection().isEmpty())
        select.enable();
      else
        select.disable();
    }
  });
  grid.addListener(Events.CellDoubleClick, new Listener<BaseEvent>() {
    public void handleEvent(BaseEvent be) {
      select();
    }
  });
  setGridProperties();
}

代码示例来源:origin: bedatadriven/activityinfo

public IndicatorGridPanel(Dispatcher dispatcher) {
  this.dispatcher = dispatcher;
  store = new ListStore<ModelData>(loader);
  grid = new Grid<ModelData>(store, createColumnModel());
  grid.setView(new HighlightingGridView() {
    @Override
    protected boolean isHighlightable(ModelData model) {
      return model instanceof IndicatorDTO;
    }
  });
  setEmptyText();
  grid.setAutoExpandColumn("name");
  grid.setHideHeaders(true);
  grid.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
  grid.getSelectionModel().addListener(Events.BeforeSelect, new Listener<SelectionEvent<ModelData>>() {
    @Override
    public void handleEvent(SelectionEvent<ModelData> event) {
      if (!(event.getModel() instanceof IndicatorDTO)) {
        event.setCancelled(true);
      }
    }
  });
  setLayout(new FitLayout());
  add(grid);
}

代码示例来源:origin: bedatadriven/activityinfo

grid = new Grid<>(store, columnModel);
grid.setLoadMask(true);
grid.setSelectionModel(new GridSelectionModel<>());
grid.getSelectionModel().addSelectionChangedListener(new SelectionChangedListener<UserPermissionDTO>() {
grid.addListener(Events.DoubleClick, new Listener<GridEvent<UserPermissionDTO>>() {
  @Override
  public void handleEvent(GridEvent<UserPermissionDTO> event) {
grid.addPlugin(allowViewAll);
grid.addPlugin(allowCreate);
grid.addPlugin(allowCreateAll);
grid.addPlugin(allowEdit);
grid.addPlugin(allowEditAll);
grid.addPlugin(allowDelete);
grid.addPlugin(allowDeleteAll);
grid.addPlugin(allowManageUsers);
grid.addPlugin(allowManageAllUsers);
grid.addPlugin(allowExport);
grid.addPlugin(allowDesign);
add(grid);

代码示例来源:origin: pl.touk/wonderful-security-lib

grid = new Grid(listStore, cm);
grid.disableEvents(false);
grid.setBorders(true);
grid.setAutoExpandMax(800);
grid.setAutoExpandColumn(expandedColumnId);
grid.addListener(Events.RowDoubleClick,new Listener<GridEvent>(){
  public void handleEvent(GridEvent ge) {
    afterGridRowDoubleClicked(ge);
  grid.addPlugin(plugin);

代码示例来源:origin: bedatadriven/activityinfo

grid = new Grid<>(store, columnModel);
grid.setAutoExpandColumn("header");
grid.setAutoExpandMin(150);
grid.setView(new PivotGridView());
grid.setSelectionModel(new CellSelectionModel<PivotGridPanel.PivotTableRow>());
grid.addListener(Events.CellDoubleClick, new Listener<GridEvent<PivotTableRow>>() {
  @Override
  public void handleEvent(GridEvent<PivotTableRow> ge) {

代码示例来源:origin: com.extjs/gxt

@Override
protected void onKeyDown(ComponentEvent ce, int index) {
 ce.cancelBubble();
 if (grid.getSelectionModel() instanceof CellSelectionModel<?>) {
  CellSelectionModel<?> csm = (CellSelectionModel<?>) grid.getSelectionModel();
  csm.selectCell(0, index);
 } else {
  grid.getSelectionModel().select(0, false);
 }
}

代码示例来源:origin: pl.touk.tola/tola

cp.setLayout(new FitLayout());
final Grid<FileDescriptorGxt> grid = new Grid<FileDescriptorGxt>(store, cm);
grid.setStyleAttribute("borderTop", "none");
grid.setAutoExpandColumn(FileDescriptorGxt.FILE_NAME);
grid.setBorders(true);
grid.addListener(Events.RowDoubleClick, new Listener<GridEvent>() {
  public void handleEvent(GridEvent ge) {
    FileDescriptorGxt ufb = grid.getSelectionModel().getSelectedItem();

代码示例来源:origin: pl.touk.top/file-upload-gwtclient-lib

this.attachmentsGrid = new Grid(listStore, columnModel);
this.attachmentsGrid.setAutoExpandColumn("fileName");
attachmentsGrid.setBorders(true);
attachmentsGrid.setSelectionModel(new KeyAndMouseSelectionModel<FileDescriptor>(attachmentsGrid) {
  @Override
  public void fireEvent(BeanModel beanModelSelected, boolean doubleClick, boolean mouseEvent) {
attachmentsGrid.setEnableColumnResize(true);

代码示例来源:origin: geoserver/geofence

/**
 * Sets the grid properties.
 */
public void setGridProperties()
{
  grid.setLoadMask(true);
  grid.setAutoWidth(true);
  if (grid.getStore() != null)
  {
    grid.getStore().setSortField(BeanKeyValue.PRIORITY.getValue());
    grid.getStore().setSortDir(SortDir.ASC);
  }
  grid.addListener(Events.ColumnResize, new ResizeListener(COLUMN_HEADER_OFFSET));
}

代码示例来源:origin: com.extjs/gxt

@SuppressWarnings({"unchecked", "rawtypes"})
@Override
public void bindGrid(Grid grid) {
 if (this.grid != null) {
  this.grid.removeListener(Events.CellMouseDown, this);
  this.grid.removeListener(Events.BeforeEdit, this);
  this.grid.removeListener(Events.ViewReady, this);
  this.grid.getView().removeListener(Events.Refresh, this);
  this.grid.getView().removeListener(Events.RowUpdated, this);
  keyNav.bind(null);
  bind(null);
 }
 this.grid = grid;
 if (grid != null) {
  grid.setTrackMouseOver(false);
  grid.addListener(Events.BeforeEdit, this);
  grid.addListener(Events.CellMouseDown, this);
  grid.addListener(Events.ViewReady, this);
  grid.getView().addListener(Events.Refresh, this);
  grid.getView().addListener(Events.RowUpdated, this);
  keyNav.bind(grid);
  bind(grid.getStore());
 }
}

代码示例来源:origin: bedatadriven/activityinfo

@Override
protected Grid<ProjectDTO> createGridAndAddToContainer(Store store) {
  grid = new Grid<ProjectDTO>((ListStore) store, createColumnModel());
  grid.setAutoExpandColumn("description");
  grid.setLoadMask(true);
  setLayout(new FitLayout());
  add(grid);
  return grid;
}

代码示例来源:origin: pl.touk.top/file-upload-gwtclient-lib

public KeyAndMouseSelectionModel(Grid grid) {
  this.grid = grid;
  grid.addListener(Events.RowDoubleClick, new Listener<GridEvent>() {
    public void handleEvent(GridEvent event) {
      KeyAndMouseSelectionModel.this.fireEvent(
          KeyAndMouseSelectionModel.this.grid.getSelectionModel().getSelectedItem(),true, true);
    }
  });
}

代码示例来源:origin: geoserver/geofence

@Override
public void setGridProperties() {
  grid.setHeight(Constants.SOUTH_PANEL_DIMENSION - 25);
  if (grid.getStore() != null) {
    grid.getStore().setSortField(BeanKeyValue.PRIORITY.getValue());
    grid.getStore().setSortDir(SortDir.ASC);
  }
  grid.addListener(Events.RowDoubleClick,
      new Listener<GridEvent<RuleModel>>() {
        public void handleEvent(GridEvent<RuleModel> be) {
          RuleModel ruleModel = be.getModel();
          Dispatcher.forwardEvent(
              GeofenceEvents.EDIT_RULE_UPDATE,
              new GridStatus(grid, ruleModel));
        }
      });
}

相关文章