I have an AjaxFallbackDefaultDataTable
which contains one row per test result. A test result may have a note attached to it, which needs to be displayed prominently below the test result, hopefully giving a table similar to the following:
| Test | Result | Appraisal |
|------|--------|-----------|
| 1 | 20.0 | PASS |
| 2 | 1.50 | FAIL |
| Note: This is an epic fail|
| 3 | 19.4 | PASS |
| 4 | 14.9 | PASS |
Is there any way to achieve this row insertion (preferably with column spanning) using the Wicket DataTable constructs. As I dig down into the source I can find Item
renderers but nothing that deals with a row.
Currently I have the following:
// Create the sortable data provider.
SortableDataProvider<TestResult> provider = new SortableDataProvider<TestResult>() {
//... hibernate pagination code ...
};
List<IColumn> columns = new ArrayList<IColumn>();
columns.add(new TextFilteredPropertyColumn(new Model<String>("Test"), "test", "test"));
columns.add(new TextFilteredPropertyColumn(new Model<String>("Result"), "result", "result"));
columns.add(new TextFilteredPropertyColumn(new Model<String>("Appraisal"), "appraisal", "appraisal"));
// Create a new AJAX table using the sortable, filtered data provider.
final AjaxFallbackDefaultDataTable dataTable = new AjaxFallbackDefaultDataTable("testResultTable", columns.toArray(new IColumn[0]), provider, 20);// 20 = number of rows per page
I don't think there is a clean way to do that, you will have to hack the resulting HTML.
I'd attach a custom behavior to the rows that generates the required HTML automatically, something like this:
new AjaxFallbackDefaultDataTable<MyCustomObject>(
id, columns, dataProvider, rowsPerPage){
@Override
protected Item<MyCustomObject> newRowItem(String id,
int index,
final IModel<MyCustomObject> model){
Item<MyCustomObject> item = super.newRowItem(id, index, model);
item.add(new AbstractBehavior(){
private static final long serialVersionUID = 1L;
/**
* {@inheritDoc}
*/
@Override
public void onRendered(Component component){
if(model.getObject().isEpicFail()){
component.getResponse().write(
"<tr><td colspan=\"3\">This is an epic fail</td></tr>");
}
}
});
return item;
}
private static final long serialVersionUID = 1L;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With