How to implement a freeze frame in GXT 3.x?

How can frozen columns be implemented in GXT 3.x (from Sencha)? Ext-JS, another product from Sencha, seems to be implementing this, but I don't see where Java GXT is implementing the same thing:

http://dev.sencha.com/deploy/ext-4.0.0/examples/grid/locking-grid.html

+7
source share
2 answers

The basic idea is that you need two different scroll containers: one with a fixed column (s), one with scrollable columns. Each of them should be in a separate viewing window, so the standard Grid / GridView does not work with this - they make assumptions about how scrolling should behave, so simply subclassing one or both will probably be quite attractive.

Instead, you can create two grids, one for locked columns, one for scrollable ones. Each of them can process its own ColumnConfig classes, draw headers and rows, and bind to the same ListStore to ensure synchronization of its data - changes to the repository will be transmitted along with both listening networks.

To get the full effect, additional wiring is required:

  • Scroll binding Listen to the BodyScrollEvent from each grid and scroll the other to the same place (changing only top , not left , since you do not want one of them to control the other).
  • Calibration is the second big part - both grids need their scrollable height to be the same, but horizontal scrolling requires a buffer at the bottom when this scroll bar is actually displayed. Usually a grid is reported about the size based on its parent instructions, although sometimes you sort the grid directly - in this case this step is not needed, just change the two grids a little. Otherwise, you will need to structure the layout in order to properly configure it.
  • Finally, a locked column requires that its vertical scrollbar be hidden β€” the user does not need to see two vertical scrollbars.

This applies to the main use case, but it doesn’t have to do with things like alternative GridView implementations - GroupingView , and subclasses need to associate the extension (and hide the group headers so that they do not appear twice, plus to deal with the fact that the group line should not be divided, when the second half scrolls to the side), TreeGridView and TreeGrid need to connect the expanding nodes and hide the +/- tree icons from the second grid.

Here, this basic set of modifications applies to the basic grid example at http://www.sencha.com/examples/#ExamplePlace:basicgrid . To avoid confusion in the problem, I removed a number of other functions in this grid, such as tooltips and changing the selection model:

 public class GridExample implements IsWidget, EntryPoint { private static final StockProperties props = GWT.create(StockProperties.class); private ContentPanel root; @Override public Widget asWidget() { if (root == null) { final NumberFormat number = NumberFormat.getFormat("0.00"); ColumnConfig<Stock, String> nameCol = new ColumnConfig<Stock, String>(props.name(), 50, SafeHtmlUtils.fromTrustedString("<b>Company</b>")); ColumnConfig<Stock, String> symbolCol = new ColumnConfig<Stock, String>(props.symbol(), 100, "Symbol"); ColumnConfig<Stock, Double> lastCol = new ColumnConfig<Stock, Double>(props.last(), 75, "Last"); ColumnConfig<Stock, Double> changeCol = new ColumnConfig<Stock, Double>(props.change(), 100, "Change"); changeCol.setCell(new AbstractCell<Double>() { @Override public void render(Context context, Double value, SafeHtmlBuilder sb) { String style = "style='color: " + (value < 0 ? "red" : "green") + "'"; String v = number.format(value); sb.appendHtmlConstant("<span " + style + " qtitle='Change' qtip='" + v + "'>" + v + "</span>"); } }); ColumnConfig<Stock, Date> lastTransCol = new ColumnConfig<Stock, Date>(props.lastTrans(), 100, "Last Updated"); lastTransCol.setCell(new DateCell(DateTimeFormat.getFormat("MM/dd/yyyy"))); List<ColumnConfig<Stock, ?>> l = new ArrayList<ColumnConfig<Stock, ?>>(); //Remove name from main set of columns // l.add(nameCol); l.add(symbolCol); l.add(lastCol); l.add(changeCol); l.add(lastTransCol); //create two column models, one for the locked section ColumnModel<Stock> lockedCm = new ColumnModel<Stock>(Collections.<ColumnConfig<Stock, ?>>singletonList(nameCol)); ColumnModel<Stock> cm = new ColumnModel<Stock>(l); ListStore<Stock> store = new ListStore<Stock>(props.key()); store.addAll(TestData.getStocks()); root = new ContentPanel(); root.setHeadingText("Locked Grid Sample"); root.setPixelSize(600, 300); final Resizable resizable = new Resizable(root, Dir.E, Dir.SE, Dir.S); root.addExpandHandler(new ExpandHandler() { @Override public void onExpand(ExpandEvent event) { resizable.setEnabled(true); } }); root.addCollapseHandler(new CollapseHandler() { @Override public void onCollapse(CollapseEvent event) { resizable.setEnabled(false); } }); //locked grid final Grid<Stock> lockedGrid = new Grid<Stock>(store, lockedCm) { @Override protected Size adjustSize(Size size) { //this is a tricky part - convince the grid to draw just slightly too wide //and so push the scrollbar out of sight return new Size(size.getWidth() + XDOM.getScrollBarWidth() - 1, size.getHeight()); } }; lockedGrid.setView(new GridView<Stock>(){{ this.scrollOffset=0; }}); //require columns to always fit, preventing scrollbar lockedGrid.getView().setForceFit(true); //main grid, with horiz scrollbar final Grid<Stock> grid = new Grid<Stock>(store, cm); //don't want this feature, want to encourage horizontal scrollbars // grid.getView().setAutoExpandColumn(nameCol); grid.getView().setStripeRows(true); grid.getView().setColumnLines(true); grid.setBorders(false); grid.setColumnReordering(true); grid.setStateful(true); grid.setStateId("gridExample"); //link scrolling lockedGrid.addBodyScrollHandler(new BodyScrollHandler() { @Override public void onBodyScroll(BodyScrollEvent event) { grid.getView().getScroller().scrollTo(ScrollDirection.TOP, event.getScrollTop()); } }); grid.addBodyScrollHandler(new BodyScrollHandler() { @Override public void onBodyScroll(BodyScrollEvent event) { lockedGrid.getView().getScroller().scrollTo(ScrollDirection.TOP, event.getScrollTop()); } }); HorizontalLayoutContainer gridWrapper = new HorizontalLayoutContainer(); root.setWidget(gridWrapper); //add locked column, only 300px wide (in this example, use layouts to change how this works HorizontalLayoutData lockedColumnLayoutData = new HorizontalLayoutData(300, 1.0); //this is optional - without this, you get a little offset issue at the very bottom of the non-locked grid lockedColumnLayoutData.setMargins(new Margins(0, 0, XDOM.getScrollBarWidth(), 0)); gridWrapper.add(lockedGrid, lockedColumnLayoutData); //add non-locked section, taking up all remaining width gridWrapper.add(grid, new HorizontalLayoutData(1.0, 1.0)); } return root; } @Override public void onModuleLoad() { RootPanel.get().add(asWidget()); } } 

There are several problems (there is no line between the locked and unlocked column, the locked icon in the context menu of the column header is a little inappropriate), but it covers most of the details without much hassle and leaves almost all of this open configuration - do you want a lock at the end? Just move the changes around - want more than one locked column? just add more to lockedCm.

+11
source

This functionality is not implemented in GXT, but there is a user named The_Jackal who made a workaround for this problem in the Sencha Forum - Topic . I have not tried it yet, but hope this can help you.

GXT - Workaround Solution for Freezing Mesh Download

+2
source

All Articles