View Full Version : add 'name' HTML attribute TreePanel nodes
Alona Oz
14 Dec 2010, 6:48 AM
Is there any possibility to set 'name' for TreePanel nodes? I need the name attribute to be a part of the created HTML. I need it for Web Testing (WebDrive).
10x
You need to override the getTemplate method in the TreePanelView to return custom markup. Why do you want to use a name attribute and not an id? Because that would work without any changes. Simple setup a keyprovider as demonstrated here http://www.sencha.com/examples/explorer.html#asynctree
Alona Oz
14 Dec 2010, 7:04 AM
Using 'id' this is an option. This is probably the best option since it doesn't seem that I want override getTemplate().
10x
Alona Oz
14 Dec 2010, 7:32 AM
Can I customize ids for Grid?
I've tried to it in the following way, but "getKey" is never called.
public void drawConversationsList(ListStore<BeanModel> conversations) {
conversations.setKeyProvider(new ModelKeyProvider<BeanModel>() {
public String getKey(BeanModel model) {
return "conversation_" + model.<String> get("id");
}
});
}
Which version do you use? GridView should call it in the latest.
Alona Oz
14 Dec 2010, 7:35 AM
I use 2.2.0
Should be in there. Please post a fully working testcase implementing EntryPoint.
Alona Oz
15 Dec 2010, 4:46 AM
The standalone test works, so there is probably some problem in my application, I will debug it.
Just another quetion is there any way to customize ids of cells in addition to rows?
10x
Just another quetion is there any way to customize ids of cells in addition to rows?
Nothing build in, but you could query for any children. Its a table, simple get the X td element while X is the index.
Alona Oz
15 Dec 2010, 7:06 AM
Ok, I've debugged my code and it seems that it's because I use LiveGridView. Below is the testcase that ignore keyProvider.
public class Hello implements EntryPoint {
public void onModuleLoad() {
LayoutContainer container = new LayoutContainer() {
ColumnModel cm;
protected void onRender(Element parent, int index) {
super.onRender(parent, index);
setLayout(new FlowLayout(10));
getAriaSupport().setPresentation(true);
final NumberFormat currency = NumberFormat.getCurrencyFormat();
final NumberFormat number = NumberFormat.getFormat("0.00");
final NumberCellRenderer<Grid<Stock>> numberRenderer = new NumberCellRenderer<Grid<Stock>>(currency);
GridCellRenderer<Stock> change = new GridCellRenderer<Stock>() {
public String render(Stock model, String property, ColumnData config, int rowIndex, int colIndex,
ListStore<Stock> store, Grid<Stock> grid) {
double val = (Double) model.get(property);
String style = val < 0 ? "red" : GXT.isHighContrastMode ? "#00ff5a" : "green";
String v = number.format(val);
return "<span qtitle='" + cm.getColumnById(property).getHeader() + "' qtip='" + v
+ "' style='font-weight: bold;color:" + style + "'>" + v + "</span>";
}
};
GridCellRenderer<Stock> gridNumber = new GridCellRenderer<Stock>() {
public String render(Stock model, String property, ColumnData config, int rowIndex, int colIndex,
ListStore<Stock> store, Grid<Stock> grid) {
return numberRenderer.render(null, property, model.get(property));
}
};
List<ColumnConfig> configs = new ArrayList<ColumnConfig>();
ColumnConfig column = new ColumnConfig();
column.setId("name");
column.setHeader("Company");
column.setWidth(200);
column.setRowHeader(true);
configs.add(column);
column = new ColumnConfig();
column.setId("symbol");
column.setHeader("Symbol");
column.setWidth(100);
configs.add(column);
column = new ColumnConfig();
column.setId("last");
column.setHeader("Last");
column.setAlignment(HorizontalAlignment.RIGHT);
column.setWidth(75);
column.setRenderer(gridNumber);
configs.add(column);
column = new ColumnConfig("change", "Change", 100);
column.setAlignment(HorizontalAlignment.RIGHT);
column.setRenderer(change);
configs.add(column);
column = new ColumnConfig("date", "Last Updated", 100);
column.setAlignment(HorizontalAlignment.RIGHT);
column.setDateTimeFormat(DateTimeFormat.getShortDateFormat());
configs.add(column);
ListStore<Stock> store = new ListStore<Stock>();
store.add(getStocks());
store.setKeyProvider(new ModelKeyProvider<Stock>() {
public String getKey(Stock model) {
return "stock_" + model.<String> get("symbol");
}
});
cm = new ColumnModel(configs);
ContentPanel cp = new ContentPanel();
cp.setBodyBorder(true);
//cp.setIcon(Resources.ICONS.table());
cp.setHeading("Basic Grid");
cp.setButtonAlign(HorizontalAlignment.CENTER);
cp.setLayout(new FitLayout());
cp.getHeader().setIconAltText("Grid Icon");
cp.setSize(600, 300);
final Grid<Stock> grid = new Grid<Stock>(store, cm);
grid.setId("myTable");
grid.setStyleAttribute("borderTop", "none");
grid.setAutoExpandColumn("name");
grid.setBorders(false);
grid.setStripeRows(true);
grid.setColumnLines(true);
grid.setColumnReordering(true);
grid.getAriaSupport().setLabelledBy(cp.getHeader().getId() + "-label");
LiveGridView liveView = new LiveGridView();
liveView.setAutoFill(true);
liveView.setRowHeight(30);
liveView.setCacheSize(20);
grid.setView(liveView);
cp.add(grid);
add(cp);
// needed to enable quicktips (qtitle for the heading and qtip for the
// content) that are setup in the change GridCellRenderer
new QuickTip(grid);
}
};
RootPanel.get().add(container);
}
public static List<Stock> getStocks() {
List<Stock> stocks = new ArrayList<Stock>();
stocks.add(new Stock("Apple Inc.", "AAPL", 125.64, 123.43));
stocks.add(new Stock("Cisco Systems, Inc.", "CSCO", 25.84, 26.3));
return stocks;
}
}
Yes LiveGridView ignores it because keyprovider is on the wrong store. I will change to code so yours works too.
Alona Oz
16 Dec 2010, 1:24 AM
Hi, Sven,
I am not sure I understood your answer. Do you mean that there is some workaround that I can use or it requires changes in LiveGridView code?
No workaround at the moment. I will try to get it into 2.2.2
Powered by vBulletin® Version 4.1.5 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.