Making a grid's checkbox column preserve its checked state across pages

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Making a grid's checkbox column preserve its checked state across pages

Davide Vecchi
Hi everybody,

The following is my scenario, I'm looking for suggestions about good ways to go about it.

Many of my pages have grids, and many of these grids have columns whose content in each row is a checkbox.

If the grid has many rows and so it gets divided into grid pages and it gets a Pager, if I check some checkboxes in the 1st page of the grid and then use the Pager to go to the 2nd page of the grid and then to go back to the 1st page, the checkboxes in the 1st page of the grid have lost their checked state and are all unchecked. I want the checkboxes to preserve their "checked" state while paging back and forth over the grid.

The checkbox is created by a <p:> tag in the page template, just before the </t:grid> closing tag. F.ex. if the Java class is MyPage.java, the grid tag in MyPage.tml will contain:

                <p:myColumnCell>

                                <input t:type="checkbox" value="myRecord.myField" .... />

                </p:myColumnCell>

In MyPage.java, myRecord is an instance field annotated with @Property .

Currently I handle this by annotating myRecord with @Persist and making sure to save into it the state of each checkbox that the user changes, so when the user goes back to page 1 the checkboxes that were checked there are still checked.

However this requires changes in MyPage.java, so if I want this behavior in other pages I must make the same changes in the Java classes of all those pages.

I'm looking for a way to make changes in only one place and have this functionality in all the pages that have a grid, without having to make changes in all the pages. In case, I'm totally open to customizing Grid.java or GridPager.java or other classes.
Reply | Threaded
Open this post in threaded view
|

Re: Making a grid's checkbox column preserve its checked state across pages

Lance Java
If you want the values serverside, you'll need to POST the form when
changing pages. You might find this difficult to achieve as paging is
currently done as a GET request.

The simplest solution would be to add a change event listener clientside
and store the values on the client until the form is submitted / saved. You
might use a hidden text field for this.
On 19 Feb 2016 9:19 a.m., "Davide Vecchi" <[hidden email]> wrote:

> Hi everybody,
>
> The following is my scenario, I'm looking for suggestions about good ways
> to go about it.
>
> Many of my pages have grids, and many of these grids have columns whose
> content in each row is a checkbox.
>
> If the grid has many rows and so it gets divided into grid pages and it
> gets a Pager, if I check some checkboxes in the 1st page of the grid and
> then use the Pager to go to the 2nd page of the grid and then to go back to
> the 1st page, the checkboxes in the 1st page of the grid have lost their
> checked state and are all unchecked. I want the checkboxes to preserve
> their "checked" state while paging back and forth over the grid.
>
> The checkbox is created by a <p:> tag in the page template, just before
> the </t:grid> closing tag. F.ex. if the Java class is MyPage.java, the grid
> tag in MyPage.tml will contain:
>
>                 <p:myColumnCell>
>
>                                 <input t:type="checkbox"
> value="myRecord.myField" .... />
>
>                 </p:myColumnCell>
>
> In MyPage.java, myRecord is an instance field annotated with @Property .
>
> Currently I handle this by annotating myRecord with @Persist and making
> sure to save into it the state of each checkbox that the user changes, so
> when the user goes back to page 1 the checkboxes that were checked there
> are still checked.
>
> However this requires changes in MyPage.java, so if I want this behavior
> in other pages I must make the same changes in the Java classes of all
> those pages.
>
> I'm looking for a way to make changes in only one place and have this
> functionality in all the pages that have a grid, without having to make
> changes in all the pages. In case, I'm totally open to customizing
> Grid.java or GridPager.java or other classes.
>
Reply | Threaded
Open this post in threaded view
|

RE: Making a grid's checkbox column preserve its checked state across pages

Davide Vecchi
The way in which I was thinking to handle this for now was to act client-side on the change of a checkbox and send its checked state to the server via Ajax, without POSTing the form. The idea of saving the states in the client instead is interesting, I had not thought about it and I will definitely explore it.

However my final goal is to avoid having to make changes (either client or server-side) in each page that has grids with checkboxes, and I was wondering if there was some existing functionality that I could exploit to somehow make the grid handle the checkbox states on its own without any "help" from the page the grid is in.

Otherwise I'm considering modifying the Grid (or the GridPager or other component) so that the component is aware of having checkbox columns and saves the checkboxes states on paging, and restores them when going back to the same grid page. Any suggestion or observation about this would be welcome.



-----Original Message-----
From: Lance Java [mailto:[hidden email]]
Sent: Friday, February 19, 2016 14:10
To: Tapestry users <[hidden email]>
Subject: Re: Making a grid's checkbox column preserve its checked state across pages

If you want the values serverside, you'll need to POST the form when changing pages. You might find this difficult to achieve as paging is currently done as a GET request.

The simplest solution would be to add a change event listener clientside and store the values on the client until the form is submitted / saved. You might use a hidden text field for this.

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]
Reply | Threaded
Open this post in threaded view
|

RE: Making a grid's checkbox column preserve its checked state across pages

h3ph3st0s
The best way is to keep a data structure seperated from your grid and this
be used as index of checked and unchecked lines,assuming each line is
identified uniquely. Updating grid upfate your structure and reverse on
page flips.
Στις 19 Φεβ 2016 15:41, ο χρήστης "Davide Vecchi" <[hidden email]> έγραψε:

> The way in which I was thinking to handle this for now was to act
> client-side on the change of a checkbox and send its checked state to the
> server via Ajax, without POSTing the form. The idea of saving the states in
> the client instead is interesting, I had not thought about it and I will
> definitely explore it.
>
> However my final goal is to avoid having to make changes (either client or
> server-side) in each page that has grids with checkboxes, and I was
> wondering if there was some existing functionality that I could exploit to
> somehow make the grid handle the checkbox states on its own without any
> "help" from the page the grid is in.
>
> Otherwise I'm considering modifying the Grid (or the GridPager or other
> component) so that the component is aware of having checkbox columns and
> saves the checkboxes states on paging, and restores them when going back to
> the same grid page. Any suggestion or observation about this would be
> welcome.
>
>
>
> -----Original Message-----
> From: Lance Java [mailto:[hidden email]]
> Sent: Friday, February 19, 2016 14:10
> To: Tapestry users <[hidden email]>
> Subject: Re: Making a grid's checkbox column preserve its checked state
> across pages
>
> If you want the values serverside, you'll need to POST the form when
> changing pages. You might find this difficult to achieve as paging is
> currently done as a GET request.
>
> The simplest solution would be to add a change event listener clientside
> and store the values on the client until the form is submitted / saved. You
> might use a hidden text field for this.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
Reply | Threaded
Open this post in threaded view
|

RE: Making a grid's checkbox column preserve its checked state across pages

Lance Java
In reply to this post by Davide Vecchi
You might be able to do that with my observe mixin

http://t5stitch-lazan.rhcloud.com/observedemo
On 19 Feb 2016 1:41 p.m., "Davide Vecchi" <[hidden email]> wrote:

> The way in which I was thinking to handle this for now was to act
> client-side on the change of a checkbox and send its checked state to the
> server via Ajax, without POSTing the form. The idea of saving the states in
> the client instead is interesting, I had not thought about it and I will
> definitely explore it.
>
> However my final goal is to avoid having to make changes (either client or
> server-side) in each page that has grids with checkboxes, and I was
> wondering if there was some existing functionality that I could exploit to
> somehow make the grid handle the checkbox states on its own without any
> "help" from the page the grid is in.
>
> Otherwise I'm considering modifying the Grid (or the GridPager or other
> component) so that the component is aware of having checkbox columns and
> saves the checkboxes states on paging, and restores them when going back to
> the same grid page. Any suggestion or observation about this would be
> welcome.
>
>
>
> -----Original Message-----
> From: Lance Java [mailto:[hidden email]]
> Sent: Friday, February 19, 2016 14:10
> To: Tapestry users <[hidden email]>
> Subject: Re: Making a grid's checkbox column preserve its checked state
> across pages
>
> If you want the values serverside, you'll need to POST the form when
> changing pages. You might find this difficult to achieve as paging is
> currently done as a GET request.
>
> The simplest solution would be to add a change event listener clientside
> and store the values on the client until the form is submitted / saved. You
> might use a hidden text field for this.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
Reply | Threaded
Open this post in threaded view
|

RE: Making a grid's checkbox column preserve its checked state across pages

Svein-2
CONTENTS DELETED
The author has deleted this message.