PDA

View Full Version : how to update the group name in a groupingview



michaels
21 Jan 2009, 7:22 AM
Hi,
I have 2 groupingView and i edit the group name with the method setGroupRenderer
(I update the number of row for each group)
It works fine when I add a line in a group, but not when I remove it ..

Thanks for the help
Have a good day

kolli
21 Jan 2009, 8:46 AM
can you post sample code of what you are trying to do?

michaels
21 Jan 2009, 9:36 AM
Of course, here it is:
both of my grid (grid1 and grid2) are defined like that:

List<ColumnConfig> columns = getGridColumnConfig();
storeGrid.groupBy("id");
final ColumnModel cm = new ColumnModel(columns);
GroupingView view = new GroupingView();
viewsetForceFit(true);
view.setGroupRenderer(new GridGroupRenderer()
{
public String render(GroupColumnData data)
{
return "row number " + Integer.toString(data.models.size()) }
}
);

Grid<BeanModel> grid = new Grid<BeanModel>(storeGrid, cm);
grid.setWidth(600);
grid.setHeight(200);
grid.setBorders(true);
grid.setView(view);


Then i define my source and target

GridDragSource gridDragSource1 = new GridDragSource(grid1);
GridDropTarget gridDropTarget1 = new GridDropTarget(grid2);
gridDropTarget1.setAllowSelfAsSource(false);
gridDropTarget1.setFeedback(Feedback.INSERT);


So if i have 3 lines in grid1 and i drop it to the grid2
it displays in grid1: line number 3 (but only 2 lines are really in the group)
it displays in grid2: line number 1 (which is correct)

The group renderer is not called for the first grid when i remove my row

Thank's for your answer, I hope I'm clear enough

gslender
22 Jan 2009, 2:08 AM
Post a full and complete example showing the problem. I've just tested a GroupingGrid with DND and it works fine.

michaels
22 Jan 2009, 3:56 AM
sure
here is a complete code:


import java.util.ArrayList;
import java.util.List;
import com.extjs.gxt.ui.client.data.BeanModel;
import com.extjs.gxt.ui.client.data.BeanModelLookup;
import com.extjs.gxt.ui.client.dnd.GridDragSource;
import com.extjs.gxt.ui.client.dnd.GridDropTarget;
import com.extjs.gxt.ui.client.dnd.DND.Feedback;
import com.extjs.gxt.ui.client.store.GroupingStore;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.extjs.gxt.ui.client.widget.grid.GridGroupRenderer;
import com.extjs.gxt.ui.client.widget.grid.GroupColumnData;
import com.extjs.gxt.ui.client.widget.grid.GroupingView;
import com.extjs.gxt.ui.client.widget.layout.FlowLayout;

public class Test_DragAndDrop extends LayoutContainer
{
public Test_DragAndDrop()
{
setLayout(new FlowLayout(10));

Grid<BeanModel> grid1 = getGrid();
Grid<BeanModel> grid2 = getGrid();

// Then i define my source and target

GridDragSource gridDragSource1 = new GridDragSource(grid1);
GridDropTarget gridDropTarget1 = new GridDropTarget(grid2);
gridDropTarget1.setAllowSelfAsSource(false);
gridDropTarget1.setFeedback(Feedback.INSERT);
add(grid1);
add(grid2);
}


public Grid<BeanModel> getGrid()
{
// column definition
List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
ColumnConfig column = new ColumnConfig("id", "id", 150);
columns.add(column);
column = new ColumnConfig("name", "name", 150);
columns.add(column);

// store
User user1 = new User("1","name1");
User user2 = new User("1","name2");
ArrayList<User> listUser = new ArrayList<User>();
listUser.add(user1);
listUser.add(user2);

List<BeanModel> listBeanModel = BeanModelLookup.get().getFactory(User.class).createModel(listUser);
GroupingStore<BeanModel> storeGrid = new GroupingStore<BeanModel>();
storeGrid.add(listBeanModel);
storeGrid.groupBy("id");

// grid definition
final ColumnModel cm = new ColumnModel(columns);
GroupingView view = new GroupingView();

view.setGroupRenderer(new GridGroupRenderer()
{
public String render(GroupColumnData data)
{
return "row number " + Integer.toString(data.models.size());
}
}
);

Grid<BeanModel> grid = new Grid<BeanModel>(storeGrid, cm);
grid.setWidth(500);
grid.setHeight(200);
grid.setBorders(true);
grid.setView(view);
return grid;
}
}
and here is the user class defintion



import java.io.Serializable;

public class User implements Serializable
{
private String id;
private String name;
public User(String id, String name)
{
this.id = id;
this.name = name;
}
public void setId(String id)
{
this.id = id;
}
public String getId()
{
return id;
}
public void setName(String name)
{
this.name = name;
}
public String getName()
{
return name;
}
}


import com.extjs.gxt.ui.client.data.BeanModelMarker;
import com.extjs.gxt.ui.client.data.BeanModelMarker.BEAN;

@BEAN(User.class)
public interface UserBeanModel extends BeanModelMarker {

}
When i drag and drop a row from the first to the second grid, the number of row in the first array doesn't change.
Thank's for your answer
Michael

sven
22 Jan 2009, 5:44 AM
You can call refresh on the view of the first grid after a valid drop on the second gird.

michaels
22 Jan 2009, 7:07 AM
thank you for your answer, it works