【问题标题】:GWT - DataGrid table with Filter in the same view / panelGWT - 在同一视图/面板中带有过滤器的 DataGrid 表
【发布时间】:2017-04-21 09:11:12
【问题描述】:

我正在尝试在我的视图中添加一个 DataGrid。 我知道 DataGrid 只能留在布局面板中,因为提供了 ProvidesResize 和 RequiresResize 接口。

问题是,我想在 DataGrid 表的顶部添加一个过滤器,过滤器不能有固定的高度,它可以更大或更小。

没有布局面板会接受多个要调整大小的子级,但布局面板本身。但是,每一层都需要以百分比设置高度,这也不行。

如果我用 CellTable 更改 DataGrid,然后在 Flow Panel 中添加两者,问题就会解决,但表格必须是可滚动的。

我需要的是 FlowLayoutPanel,但 GWT 中没有这样的面板

我在想唯一的方法是尝试创建一个自定义面板来实现 ProvidesResize 和 RequiresResize 接口。

这是使用 LayoutPanel 的样子:

    <g:layer left="2%" right="68%" top="2%" bottom="93%">                                   
        <g:Label ui:field="gridBlurb" addStyleNames="{res.viewStandardStyle.viewTitle}" />
    </g:layer>

    <g:layer left="2%" right="68%" top="9%" bottom="56%">                                   
        <g:SplitLayoutPanel>
            <g:center>
                <g:HTMLPanel>
                    <g:FlowPanel ui:field="criteriaPanel" visible="false" />
                    <g:FlowPanel>
                        <g:Button ui:field="refresh">
                            <ui:text from="{text.refreshButtonCaption}" />
                        </g:Button>
                    </g:FlowPanel>
                </g:HTMLPanel>
            </g:center>
        </g:SplitLayoutPanel>
    </g:layer>

    <g:layer left="2%" right="2%" top="45%" bottom="5%">                                    
        <g:SplitLayoutPanel>
            <g:center>
                <c:DataGrid ui:field='table' />
            </g:center>
        </g:SplitLayoutPanel>
    </g:layer>

    <g:layer left='2%' right='2%' top="95%" bottom="0%">                                    
        <g:HTMLPanel>
            <table style="width:100%">
                <tr>
                    <td align='center'>
                        <c:SimplePager ui:field='pager' />
                    </td>
                </tr>
            </table>
        </g:HTMLPanel>
    </g:layer>

</g:LayoutPanel>

谁能帮我解决这个问题? 非常感谢。

【问题讨论】:

  • RequiresResize 默认 GWT 面板在这种情况下都不够好。

标签: gwt datagrid layoutpanels


【解决方案1】:

看起来 CSS 成功了。 非常感谢。 这就是它的样子:

<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
             xmlns:g="urn:import:com.google.gwt.user.client.ui" 
                xmlns:c="urn:import:com.google.gwt.user.cellview.client">

    <ui:with field='res' type='com.vsg.vraweb.client.resource.Resources' />
    <ui:with field='text' type='com.vsg.vralang.client.GlobalConstants' />


    <!-- 

        CSS Tricks tutorial : https://css-tricks.com/snippets/css/a-guide-to-flexbox/ 

        1) 'display: flex;' - enables a flex context for all its direct children. 

        2) 'flex-direction: row | row-reverse | column | column-reverse;' - This establishes 
        the main-axis, thus defining the direction flex items are placed in the flex 
        container.

        3) flex-grow: <number>; - This defines the ability for a flex item to grow if necessary. 
    -->

    <ui:style>
        .container {
            display: flex;
            flex-direction: column;
        }

        .dataGrid {  
            width: 100%;
            flex-grow: 1;
        }
    </ui:style>

    <g:FlowPanel addStyleNames="{style.container}">
        <g:Label ui:field="gridBlurb" addStyleNames="{res.viewStandardStyle.viewTitle}" />
        <g:HTMLPanel>
            <g:FlowPanel ui:field="criteriaPanel" visible="false" />
            <g:FlowPanel>
                <g:Button ui:field="refresh">
                    <ui:text from="{text.refreshButtonCaption}" />
                </g:Button>
            </g:FlowPanel>
        </g:HTMLPanel>
        <c:DataGrid ui:field='table' addStyleNames="{style.dataGrid}"/>
        <g:HTMLPanel>
            <table style="width:100%">
                <tr>
                    <td align='center'>
                        <c:SimplePager ui:field='pager' />
                    </td>
                </tr>
            </table>
        </g:HTMLPanel>
    </g:FlowPanel>

</ui:UiBinder>

【讨论】:

    【解决方案2】:

    如果您不关心非常旧的浏览器,请使用 flexbox CSS layout model - 我一直将它与 DataGrid(以及其他所有内容)一起使用。

    然后您只需将 display: flex; 添加到您的容器(即您使用 LayoutPanel 的内容),然后在您的 DataGrid 上设置 flex-grow: 1。这将告诉 DataGrid 在容器中的其他小部件呈现后占用所有可用空间。

    附:在过去的几年里,出于性能原因,我尽量避免使用 LayoutPanel,尤其是在移动设备上。

    【讨论】:

      猜你喜欢
      • 2013-12-08
      • 2020-12-03
      • 2015-06-08
      • 2018-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多