PDA

View Full Version : Generating and Rendering Grid rows from a sequence column in underlying Store



RCobb1
31 Oct 2011, 5:40 AM
Hello all,

I'm using GXT 2.2.4 under GWT 2.4.0... All things are working as expected, but I am struggling with two aspects of a new app I'm working on and thought I would turn to the more seasoned experts for a suggestion on how best to resolve them. I have a form that contains a few text fields and a grid widget; the grid rows come from a DTO bean. I'm trying to set a sequence on the rows both on page render (the underlying OpenJPA entity contains a collection of children that are ordered using the @OrderBy annotation on a sequence column in the child entity). I've confirmed that the @OrderBy column IS putting the collection in the proper sequence but:

Problem 1: When the Grid renders, I get a random ordering of rows in the underlying ListStore even though I am adding them to the store in the same order. Is there a way to force displaying of the rows in the grid based on a sequence field from an element in the store?

Problem 2: If the end user adds a new item to the grid, I need to reset the sequence in all items in the store to match what is in the grid (grid supports drag and drop so the end user can put the grid-rows into a sequence that they want); I've been able to do this, somewhat inelegantly, but my real question is: is there a way to access the value of the RowNumberer assigned value to the row upon an action so I can use that to assign the sequence upon persist?

Caveat: My data is coming from a legacy OpenJPA DAO package, so I'm not allowed to change any of it. As a result, I'm converting my data from entities into DTO's that extend BaseTreeModel in my services and converting them back to entities before passing back to the DAO for persistence.

Thanks in advance to all for any suggestions!

Cheers,
Randy

sven
31 Oct 2011, 5:43 AM
Problem 1: When the Grid renders, I get a random ordering of rows in the underlying ListStore even though I am adding them to the store in the same order. Is there a way to force displaying of the rows in the grid based on a sequence field from an element in the store?


The rows are normally rendered the exact same order they are in the store. I never saw a different behaviour. You can manually sort the store on any field of your model.

RCobb1
31 Oct 2011, 6:47 AM
Thank you for the reply. I'll look into trying to sort the store before rendering the grid; I just find it odd that every time I've used the debugger to look at the data returned from the service that the child records are in the proper sequence, but show up in different orders when rendered... I guess it could be that I'm not properly converting them to DTOs and putting them in the store correctly.

Thanks again for the suggestion!

Cheers,
Randy

RCobb1
31 Oct 2011, 7:55 AM
Thanks again... I got the Grid sorted properly now.

Anyone still have any input on my "problem 2" from above? My non-optimal solution is to iterate through the store on save and reset the item's sequence based on the index of the row; I can't believe that would be the most efficient mechanism.

Thanks again!
Randy

Colin Alworth
31 Oct 2011, 4:30 PM
Trying to understand your second issue - you are trying to pass the info to the server that element with ID 543 has moved to position 4?

Assuming so: is Drag/Drop the only way of reordering? Then perhaps listen on the drop, and check the new index there. You can also ask the store for the index of a given element - this could allow you to pass more messages to the server and specify what changes need to be made according to the user's changes.

Finding a general solution for all update/add/remove as well as reordering of data isn't easy (unless you are willing to just replace everything on every save), depending on how you notify your persistence mechanism of the order. If you can build a 'order' field, then you could consider dropping the row numberer altogether, and just use a GridCellRenderer that draws the 'order' field (plus one, users don't like zero indexed data). Then on DnD, update the order fields, and send those changes to the server like any other change in the data.

RCobb1
1 Nov 2011, 6:41 AM
Colin,

In essence, yes. The server-side service already handles the new or updated entity correctly, I was more concerned with efficiency and speed at the client; in a nutshell, is there a more efficient way of setting the sequence column programmatically than iterating over the store and setting the sequence based on the row index? It sounds, however, that you suggest removing the RowNumberer and using the sequence column itself (which DOES exist in the underlying row bean, but just isn't displayed in the grid) instead and adding a cell renderer and updating on drag-and-drop. This would most likely be alot more efficient because I may not need to have to iterate through grid rows each time the parent record is saved.

Thanks for the suggestion!

Cheers!
Randy