- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
正在开发需要 CellTable 之类的东西来显示和编辑数据的 GWT 应用程序。我有一些额外的要求,但我在 CellTable 示例中没有看到:
多个标题行。我实际上并不需要这样的标题行,但是每隔几行(4-10)数据我就想要一个类似标题的东西(基本上解释了接下来的“n”个项目是如何相关的)
<根据某些数据(当前日期和对象中指定的日期),某些字段应该是不可编辑的。我找到了有关如何使列不可编辑的示例,但是如何将其映射回自定义渲染器中的实际数据? (即与行对应的数据对象 - 应该很容易,但我错过了一些东西......)
我可以使用 CellTable 执行此操作吗?我应该寻找更好的小部件吗?我知道我可以在网格中完成这一切,但 CellTable 看起来更好!
谢谢。
扩展托马斯·布罗耶(Thomas Broyer)下面的答案,我已经设法让不可编辑的东西继续下去。我从来没想过“标题行”会很容易,所以编辑是主要部分。
正如我在下面评论的那样,我没有找到任何简单、易于理解的示例来向我展示整个情况。我设法从几个不同的来源将其拼凑在一起。
如果有人有任何评论或者我错过了一些明显的事情:请告诉我!
// Step 1: Create a cell (in this case based on text)
class MyEditTextCell extends EditTextCell {
@Override
public void render(com.google.gwt.cell.client.Cell.Context context,
String value, SafeHtmlBuilder sb)
{
bool editable = true;
// TODO: What goes here?
if (!editable) {
sb.appendHtmlConstant("<div contentEditable='false' unselectable='true'>" + value + "</div>");
}
else {
super.render(context, value, sb);
}
}
}
// It gets used to add a column to the table like this
final MyEditTextCell myCell = new MyTextCell();
Column<RowType, String> nmyCol = new Column<RowType, String>(myCell) {
@Override
public String getValue(RowType o) {
return o.someMethod(); // This gets the particular row out of your column.
}
};
table.addColumn(myCol, "Heading");
所以所有这些工作都相当容易,但我仍然无法弄清楚使用该行的 TODO。这一切都与另一个涉及 KeyProviders 的示例结合在一起。 KeyProvider 提供了从单元格的 render() 方法中获取的上下文以及单元格所属的行的链接。它通过索引(只是一个对象)来完成此操作。
所以你最终会得到:
// Step 2: Cell can get the row and use it to decide how to draw.
class MyEditTextCell extends EditTextCell {
@Override
public void render(com.google.gwt.cell.client.Cell.Context context,
String value, SafeHtmlBuilder sb)
{
Object key = context.getKey();
// What the key is is uo to you: if could be an Integer that indexes into
// a collection of objects, it could be a key for a hashmap. I'm guessing
// it could even be the real object itself (but I haven't tried that...)
// e.g.
boolean editable = true;
int index = ((Integer)key).intValue();
RowType row = myRowCollection.get(index);
if (row != null) {
if (/*some condition on the row*/) {
editable = false;
}
}
if (!editable) {
sb.appendHtmlConstant("<div contentEditable='false' unselectable='true'>" + value + "</div>");
}
else {
super.render(context, value, sb);
}
}
}
// Key provider links gets a unique id from the rows - I just used an in.
// This gets provided to the CellTable on creation
// e.g. CellTable tab = new CellTable(LEY_PROVIDER);
//
private static final ProvidesKey<RowType> KEY_PROVIDER = new ProvidesKey<RowType>() {
public Object getKey(RowType item) {
return Integer.valueOf(item.getId());
}
};
最佳答案
- Multiple header rows. I don't really need a header row as such, but every few rows (4-10) of data I'd like something like a header (basically explains how the next 'n' items are related)
(又名分组行)
GWT 2.5(将在一个月左右发布)将添加 CellTableBuilder
,它允许您更改 CellTable
从其 构建其 View 的方式型号。
您可以在此处查看一个示例(但与您的用例不同:添加子行而不是分组行):http://showcase2.jlabanca-testing.appspot.com/#!CwCustomDataGrid
在您的情况下,棘手的部分是检测何时插入分组行。
- Based on some data (current date and dates specified in an object), some of the fields should be non editable. I've found examples on how to make a column non editable, but how do I map that back through to actual data from the custom renderer? (i.e. the data object corresponding to the row - should be easy, but I'm missing something...)
你最好的选择是使用一个自定义的Cell
,它接受一个行对象值(这样它就可以决定单元格是否应该可编辑),但只显示/编辑一个该对象的字段/属性。
如果值可编辑,您应该能够将渲染和事件处理推迟到 TextInputCell
或 EditTextCell
,否则推迟到 TextCell
。/p>
棘手的部分是使列可编辑的条件是否取决于本身可编辑的属性。在这种情况下,您必须触发表的刷新(至少是修改的行),以便刷新有条件可编辑列。
在这种情况下,我认为使用自定义 Cell
会有更好的机会,它最初总是呈现相同的效果,但可以切换到可编辑模式(类似于 EditTextCell
);并在处理事件时执行is that value editable计算,并有条件地拒绝切换到编辑模式。
您应该能够从此处的 EditTextCell
复制/粘贴大量内容。
关于java - GWT CellTable 或类似的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10875554/
我正在使用 GWT 创建一个应用程序。该应用程序有一个搜索工具,可以提供要添加到单元格表中的列表。第一次,当 celltable 加载列表时,它显示加载动画。但是,对于替代负载,它没有显示出来。无论如
我正在使用 CellTable 向其中添加列。 当我在每个单元格上添加行和单个数据时,它工作正常。 它有像 Name ,Age, Address 这样的标题,下面的行包含值 我现在想在最后一个 Act
有人知道这是否可以根据显示行的某些值向 CellTable 添加一列? 通常使用 addColumn 但仅在 getValue 方法中启用对行属性的访问。我需要更早地获得此访问权限,以决定向列添加一些
我能够使用 celltablebuilder 构建自定义行。单击特定 anchor 单元格时,我可以为该行构建其他子行。这个子行有按钮,当点击按钮时我做了一些 Action 。我可以在子行中添加带有
我正在尝试实现一个带有自定义列标题的 CellTable,它在普通列文本下方显示一个 SearchBox(简单文本框)。 SearchBox 应该允许用户过滤 CellTable。它应该是这样的:
我有一个 Gwt 单元格表。单击标题可对列进行正确排序。 但是在页面加载时,默认情况下不会对列进行排序。 我想在页面加载时对最右边的列进行排序。 最佳答案 为了澄清一些现有的答案... a cellT
是否可以设置CellTable的列宽?在 GWT 中? 最佳答案 编辑:从 GWT 2.2 开始支持 table.setWidth 和 table.setColumnWidth table.setWi
当我在包含多列的 CellTable 中选择一行时,整行都会变成黄色。它不取决于我单击行的哪个区域(行的哪一列)。 我尝试做的是,只要没有选择该表的其他行,就将所选行保持为黄色。目前,只要我单击浏览器
我正在尝试使用他们的 ListDataProvider 排序示例作为引用对 GWT 中的列进行排序 http://code.google.com/webtoolkit/doc/latest/DevGu
我需要 GWT CellTable 的“自定义选择模型”。 CellTable 中的其中一列是复选框列。 基本要求(均适用于以下解决方案): - 单击行(不是在复选框上),选择该行并取消选择所有其他行
我正在使用 CellTable,我想在将鼠标悬停在任何单元格上时显示工具提示。我的代码运行良好,但工具提示没有改变其位置。 我的意思是,如果我将鼠标悬停在单元格 1 上显示工具提示,然后如果我将鼠标悬
我正在使用 GWT 的单元格表。我正在尝试根据用户名对列的数据进行排序。但无论如何它没有得到排序。我正在关注以下链接。 http://gwt.google.com/samples/Showcase/S
为了不重复代码,我前段时间决定重构我对使用编辑器框架的看法。目前,每个 View 都是包含其他编辑器集的编辑器。例如“人物详细信息” View 包含诸如“人物地址”、“人物图像”、“人物描述”等编辑器
重要::此问题与另一个问题完全不同 similarly titled关于 Stack Overflow 的问题。 在 GWT 2.5.1 中,我有一个 CellTable 与 RPC 支持的 Asyn
我有 4 列的 celltable(名称大小 addedBy modifiedBy ) 所有值都在运行时填充。 表格实际上显示了文档。 文档可以是pdf、txt、doc等 我想在文档名称前添加图标。
我正在使用 GWT 2.5 创建一个带有可排序日期列的 CellTable。 我的代码如下: CellTable table = new CellTable(); table.setRowStyles
我正在使用 CellTable 并希望在某些情况下以编程方式更改某些单元格的背景颜色。我按照文档中的描述使用自定义单元格进行了尝试,并使用以下命令更改了背景颜色 sb.appendHtmlConsta
我正在使用 GWT 2.1.0.M3 中的 CellTable。有 removeColumn 函数,但没有 removeAllColumns 或任何东西。由于“columns”是 CellTable
我的 GWT Projekt 中有一个 CellTable,每行都有一个 CheckBox。我需要以某种方式遍历 cellTable 中的所有行并需要检查每行的 CheckBox 是否被选中。 我不知
我有一个 GWT CellTable,它使用某种复杂而乏味的过程进行填充。我希望用户能够打印或导出该表中的数据。 我宁愿不重新呈现表格内容以进行导出,因为这是一个乏味的过程。 如何从我的 CellTa
我是一名优秀的程序员,十分优秀!