简体   繁体   English

使用输入和/或链接装饰Tapestry Grid,以设置每页的自定义行数

[英]Decorating Tapestry Grid with input and/or links for setting custom number of rows per page

it's me again :) 又是我 :)

I'm trying to extend the following behaviour of Tapestry Grid in the following way. 我试图通过以下方式扩展Tapestry Grid的以下行为。

At the moment, I can select how many rows per page I want displayed like this: 目前,我可以选择每页显示的行数,如下所示:

<t:grid class="t-form-loop"
    t:source="myGridDataSource"
    t:model="myBeanModel"
    t:row="myEntry"
    t:encoder="myEncoder"
    t:rowsPerPage="20"
    t:pagerPosition="both"
    t:rowIndex="currentIndex"
    t:inplace="true">

I would like the part with rowsPerPage to be dynamically changeable, meaning user could click on one of the predefined amounts (10,20,50,100) or simply enter his own desired amount of rows displayed per page. 我希望rowsPerPage的部分可以动态更改,这意味着用户可以单击其中一个预定义的数量(10,20,50,100),或者只需输入每页显示的所需行数。

One dirty (and not smart way to do this) is to provide the links/imput for that and save it in a variable on my page, so the Grid could reference it like this: 一个脏(而不是聪明的方法)是为它提供链接/输入并将其保存在我的页面上的变量中,因此Grid可以像这样引用它:

t:rowsPerPage="myRowsPerPage"

However, assume I have, for example, 20-30 pages. 但是,假设我有20-30页。 Adding the same code on each and every one of them would be useless and stupid, so I'd assume I'd want to decorate the existing grid somehow. 在每一个上添加相同的代码将是无用的和愚蠢的,所以我假设我想以某种方式装饰现有的网格。 However, I would not like to do this globally, since on some pages I would like to offer this functionality and on some not. 但是,我不想在全球范围内这样做,因为在某些页面上我想提供此功能,而有些则不是。

So, given my limited knowledge of Tapestry, I'd assume I have 2 options: 所以,鉴于我对Tapestry的了解有限,我假设我有两个选择:

  1. Mixin that would add the following functionality to selected Grids Mixin将为选定的网格添加以下功能
  2. Extend Grid component in a way that is has the following 2 parameters: 以具有以下2个参数的方式扩展Grid组件:

    a. 一种。 t:rowsPerPageValues="10,20,50,100"
    b. t:rowsPerPageInput="true"

Also, I'd like to know how many rows are currently displayed. 另外,我想知道当前显示的行数。

What is the best approach to this problem and could I have some help/tips with implementing them? 解决这个问题的最佳方法是什么?我可以提供一些帮助/提示来实现它们吗?

Edit: I'd like it to look something like this (sry for bad HTML): http://jsfiddle.net/ZST4E/1/ 编辑:我希望它看起来像这样(sry for bad HTML): http//jsfiddle.net/ZST4E/1/

I think you should create a new component which has an embedded t:grid . 我认为你应该创建一个具有嵌入式t:grid的新组件。 You might find that publishParameters will help. 您可能会发现publishParameters会有所帮助。

eg: 例如:

ExtendedGrid.java ExtendedGrid.java

public class ExtendedGrid {
   @Component(id="grid", publishParameters="source,inplace,etc,etc")
   private Grid grid;

   @Property
   private int rowsPerPage;
}

extendedGrid.tml extendedGrid.tml

<t:container xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd">
   <t:form zone="gridZone">
      <t:select t:id="rowsPerPage" model="[10,20,50,100]" /> <t:submit />
   </t:form>
   <t:zone t:id="gridZone">
      <t:grid t:id="grid" rowsPerPage="prop:rowsPerPage" />
   </t:zone>
</t:container>

page.tml page.tml

<t:extendedGrid source="mySource" inplace="true" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM