How to insert 'sub-rows' into a Wicket DataTable

末鹿安然 提交于 2019-12-01 01:54:54

问题


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

回答1:


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;

}



回答2:


If look at class NavigationToolbar (extension, DataTable) when looking from point of view HTML there is one row of html table, object construction is quite different but result is good, other data are presented in HTML row not being a row in sense Java table (from code that navigator isn't part of object table, is external from such point of view.

Nice fragment code to analyse

When my enriched Datatable for data will be platform to visually present reports with subtotal, I know this will be possible



来源:https://stackoverflow.com/questions/3822324/how-to-insert-sub-rows-into-a-wicket-datatable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!