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

StackOverflow https://stackoverflow.com/questions/23237613

سؤال

it's me again :)

I'm trying to extend the following behaviour of Tapestry Grid in the following way.

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.

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:

t:rowsPerPage="myRowsPerPage"

However, assume I have, for example, 20-30 pages. 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:

  1. Mixin that would add the following functionality to selected Grids
  2. Extend Grid component in a way that is has the following 2 parameters:

    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/

هل كانت مفيدة؟

المحلول

I think you should create a new component which has an embedded t:grid. You might find that publishParameters will help.

eg:

ExtendedGrid.java

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

   @Property
   private int rowsPerPage;
}

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

<t:extendedGrid source="mySource" inplace="true" />
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top