Hi guys, so i finally made the GridIndex component. But something is
bothering me and I wonder if I can improve it. The component still need the
page to implement an idx property, i wonder if I can pull it directly from
grid rowIndex parameter. Here's the code for my component.

page tml

<t:grid t:id="grid" t:source="cities" t:row="city" rowIndex="idx"
t:inPlace="true"
t:add="no" t:exclude="id" t:reorder="no" class="table table-striped">
<p:noCell>
<t:mreunionlabs.GridIndex idx="idx" grid="grid"/>
</p:noCell>
</t:grid>

page java properties

@InjectComponent
@Property
private Grid grid;

@Property
private int idx;

The component code

public class GridIndex {

    // Parameters

    @Parameter(required = true)
    @Property
    private int idx;

    @Parameter(required = true)
    @Property
    private Grid grid;

    @BeginRender
    void begin(MarkupWriter writer) {
        int no = grid.getRowsPerPage() * (grid.getCurrentPage() - 1) + idx
+ 1;
        writer.write(String.valueOf(no));
    }

}


On Fri, Apr 20, 2018 at 2:34 PM, abangkis <abang...@gmail.com> wrote:

> Hi chris and geoff, I guess creating a component or mixin is the best
> approach. Thanks.
>
> On Thu, Apr 19, 2018 at 5:12 PM, JumpStart <geoff.callender.jumpstart@
> gmail.com> wrote:
>
>> Or a mixin?
>>
>>         http://jumpstart.doublenegative.com.au/jumpstart/examples/
>> lang/creatingmixins
>>         http://jumpstart.doublenegative.com.au/jumpstart/examples/
>> tables/gridbeanmodel1
>>
>> Geoff
>>
>> > On 19 Apr 2018, at 2:20 pm, Chris Poulsen <mailingl...@nesluop.dk>
>> wrote:
>> >
>> > Create a component?
>> >
>> > --
>> > Chris
>> >
>> > On Thu, Apr 19, 2018 at 5:53 AM, abangkis <abang...@gmail.com> wrote:
>> >
>> >> Hi, when adding a custom no field to my grid, to show the no of the
>> actual
>> >> row, i declared an int on the page and calculate the value by
>> multiplying
>> >> the variables in the grid like the code bellow.
>> >>
>> >> Is there a way to do this automatically, since for now i'm doing it
>> >> manually by copy and pasting the code to every page that uses grid.
>> >>
>> >> Thank you verymuch
>> >>
>> >> <table t:id="grid" t:type="grid" t:source="loans" t:row="loan"
>> >> rowIndex="idx" t:inPlace="true"
>> >>       t:add="no">
>> >>    <p:noCell>
>> >>        ${idx}
>> >>    </p:noCell>
>> >> </table>
>> >>
>> >> @InjectComponent
>> >> private Grid grid;
>> >>
>> >> private int idx;
>> >>
>> >>
>> >> public void setIdx(int idx) {
>> >>    this.idx = idx;
>> >> }
>> >>
>> >> public int getIdx() {
>> >>    return grid.getRowsPerPage() * (grid.getCurrentPage() - 1) + idx +
>> 1;
>> >> }
>> >>
>> >>
>> >> --
>> >> http://www.mreunionlabs.net/ <http://www.mreunion-labs.net/>
>> >> twitter : @mreunionlabs @abangkis
>> >> page : https://plus.google.com/104168782385184990771
>> >>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
>> For additional commands, e-mail: users-h...@tapestry.apache.org
>>
>>
>
>
> --
> http://www.mreunionlabs.net/ <http://www.mreunion-labs.net/>
> twitter : @mreunionlabs @abangkis
> page : https://plus.google.com/104168782385184990771
>



-- 
http://www.mreunionlabs.net/ <http://www.mreunion-labs.net/>
twitter : @mreunionlabs @abangkis
page : https://plus.google.com/104168782385184990771

Reply via email to