grandanat
12 Apr 2010, 7:07 AM
Simplified problem:
I have a grid with a CheckBoxSelectionModel and i want to change default checkbox icons with my own, programmatically. Basically i think the best solution would be to extend gxt CheckBoxSelectionModel class and create a method setIcon(String imageUrl) that points to my image. I tried following code in my CustomCheckBoxSelectionModel ctor but it dowsn't work properly, it just append my image right to default image.
public CustomCheckBoxSelectionModel(String myImage) {
super();
this.getColumn().setRenderer(new GridCellRenderer<M>() {
public String render(M model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<M> store,
Grid<M> grid) {
config.cellAttr = "rowspan='2'";
config.style = "background-image: url(" + myImage + ");";
return "<div class='x-grid3-row-checker'> </div>";
}
});
}
I just want to replace this image :
.x-grid3-row-checker, .x-grid3-hd-checker {
background-image:url(../images/default/grid/row-check-sprite.gif);
}
With my own one. Can anyone advice me how to approach the problem ?
Extended problem.
If i want to use a larger image then toggle selection area will have to be increased. Although size of this area is defined din css file. How do i change it dynamically in code ? I don;t want to override css, since i don;t want to apply this change to all grids that uses a checkbox selection model.
Another abandoned solution was to use a custom identifier instead of checker
void replaceDivs() {
grid.addListener(Events.ViewReady, new Listener<ComponentEvent>() {
@Override
public void handleEvent(ComponentEvent be) {
El header = grid.getView().getHeader().el();
El headerBody = header.getChild(1);
header.setInnerHtml(header.getInnerHtml().replace("-checker", "-mychecker"));
El hdc = headerBody.child("div.x-grid3-hd-checker");
if (hdc != null) {
hdc.child("x-grid3-hd-checker");
hdc.getId();
hdc.getParent().setStyleName(hdc.getParent().getStyleName().replace("-checker", "-mychecker"));
hdc.getChild(0).getParent().setStyleName(
hdc.getChild(0).getParent().getStyleName().replace("-checker", "-mychecker"));
}
}
});
}
This solution worked better but is not really ok. i shouldn't have different different css classes for same thing(even icons are different).
I have a grid with a CheckBoxSelectionModel and i want to change default checkbox icons with my own, programmatically. Basically i think the best solution would be to extend gxt CheckBoxSelectionModel class and create a method setIcon(String imageUrl) that points to my image. I tried following code in my CustomCheckBoxSelectionModel ctor but it dowsn't work properly, it just append my image right to default image.
public CustomCheckBoxSelectionModel(String myImage) {
super();
this.getColumn().setRenderer(new GridCellRenderer<M>() {
public String render(M model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<M> store,
Grid<M> grid) {
config.cellAttr = "rowspan='2'";
config.style = "background-image: url(" + myImage + ");";
return "<div class='x-grid3-row-checker'> </div>";
}
});
}
I just want to replace this image :
.x-grid3-row-checker, .x-grid3-hd-checker {
background-image:url(../images/default/grid/row-check-sprite.gif);
}
With my own one. Can anyone advice me how to approach the problem ?
Extended problem.
If i want to use a larger image then toggle selection area will have to be increased. Although size of this area is defined din css file. How do i change it dynamically in code ? I don;t want to override css, since i don;t want to apply this change to all grids that uses a checkbox selection model.
Another abandoned solution was to use a custom identifier instead of checker
void replaceDivs() {
grid.addListener(Events.ViewReady, new Listener<ComponentEvent>() {
@Override
public void handleEvent(ComponentEvent be) {
El header = grid.getView().getHeader().el();
El headerBody = header.getChild(1);
header.setInnerHtml(header.getInnerHtml().replace("-checker", "-mychecker"));
El hdc = headerBody.child("div.x-grid3-hd-checker");
if (hdc != null) {
hdc.child("x-grid3-hd-checker");
hdc.getId();
hdc.getParent().setStyleName(hdc.getParent().getStyleName().replace("-checker", "-mychecker"));
hdc.getChild(0).getParent().setStyleName(
hdc.getChild(0).getParent().getStyleName().replace("-checker", "-mychecker"));
}
}
});
}
This solution worked better but is not really ok. i shouldn't have different different css classes for same thing(even icons are different).