0
我創建了一個「ColorCell」,它只是顯示一個顏色塊。但是,如果我將它放在一列中,則排序是「逐個」,意味着ColorCell後面的任何列對之前的列進行了排序。刪除ColorCell可以解決問題。發生什麼事?這是單元格的代碼並添加到表格中。GWT單元格導致排序問題
colorColumn.setSortable(false);
table.addColumn(colorColumn);
table.setColumnWidth(colorColumn, "16px");
ColumnSortEvent.ListHandler<HasMeasures> columnSortHandler = new ColumnSortEvent.ListHandler<HasMeasures>(
resultsDataProvider.getList());
table.addColumnSortHandler(columnSortHandler);
... code that adds other columns to sortHandler
public class ColorCell<C> implements Cell<C> {
interface Template extends SafeHtmlTemplates {
@Template("<div></div><div>{0}</div>")
SafeHtml noColorCell(SafeHtml cellContents);
/**
* The wrapper around the image vertically aligned to the bottom.
*/
@Template("<div style=\"width:14px;height:14px;float:left;background-color:{0};\"></div>")
SafeHtml colorBlockCell(String color);
}
/**
* The default spacing between the icon and the text in pixels.
*/
private static final int DEFAULT_SPACING = 4;
private static Template template;
public ColorCell() {
this(DEFAULT_SPACING);
}
public ColorCell(int spacing) {
if (template == null) {
template = GWT.create(Template.class);
}
}
public boolean dependsOnSelection() {
return false;
}
public Set<String> getConsumedEvents() {
return null;
}
public boolean handlesSelection() {
return false;
}
public boolean isEditing(Context context, Element parent, C value) {
return false;
}
public void onBrowserEvent(Context context, Element parent, C value,
NativeEvent event, ValueUpdater<C> valueUpdater) {
}
public void render(Context context, C value, SafeHtmlBuilder sb) {
String color = getColorUsed(context, value);
if (color != null) {
sb.append(template.colorBlockCell(color));
}
}
public boolean resetFocus(Context context, Element parent, C value) {
return true;
}
public void setValue(Context context, Element parent, C value) {
}
/**
* Check if the icon should be used for the value. If the icon should not be
* used, a placeholder of the same size will be used instead. The default
* implementations returns true.
*
* @param value the value being rendered
* @return true to use the icon, false to use a placeholder
*/
protected String getColorUsed(Context context, C value) {
return null;
}
/**
* Get the parent element of the decorated cell.
*
* @param parent the parent of this cell
* @return the decorated cell's parent
*/
private Element getCellParent(Element parent) {
return parent; //.getChild(1).cast();
}
}
我將addColumn代碼添加到原始文章。我沒有兩次傳入相同的頭文件,它的簡單字符串標頭名稱。 – Joel 2012-07-25 15:45:16
顯然,這可以修復它... addColumn(colorColumn,「」)。雖然現在我遇到樣式問題,因爲標題現在是非空話。 – Joel 2012-07-25 16:08:54