我创建了一个“ColorCell”,它只显示了一块颜色。但是,如果我将其放在一列中,则排序是“一个一个”,这意味着ColorCell之后的任何列都会在之前对列进行排序。删除ColorCell可以解决问题。怎么了?这是单元格的代码并添加到表格中。
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();
}
}
答案 0 :(得分:1)
您是否使用与下一个/上一个标题相同的标题添加ColorCell?这将合并ColorCell的标题并添加collspan。我的猜测是它可能导致以下列的列索引不正确。