【发布时间】:2015-04-15 16:14:14
【问题描述】:
(Cross posted here - with code sample)
我已经在我的项目中实现了WTableView,但它默认使用分页按钮而不是使用虚拟滚动(并且以非常丑陋的方式进行。)即使我几乎完全按照示例库,它仍然这样做。
我正在设置一个独立的示例,但基本上我有以下容器层次结构:
WApplication -> WTemplate -> WTabWidget -> ReportTab
ReportTab 是我想要包含表格的小部件。我尝试将其设为WContainerWidget 和WTemplate,这没有任何区别。
直接使用QueryModel<> 与我自己的扩展QueryModel(主要基于VirtualModel)的实现也没有真正的区别。
根据我的阅读,WTableView 应该只在浏览器不支持 JS 时实现分页。但我的问题出现在我尝试过的所有浏览器上。
代码示例:
auto table_view = new Wt::WTableView();
auto model = new ReportTableModel(10); // TODO change magic number
auto query = session_.query<Item>(
"SELECT"
" TaskResult, "
" sp.stockpile_label, "
" event_created, "
" FROM task_results TaskResult"
" INNER JOIN tasks t ON TaskResult.task_result_id = t.id"
" INNER JOIN stockpile_events sp ON t.id = sp.stockpile_event_id"
);
model->setQuery(query);
model->setBatchSize(10);
model->addColumn("sp.stockpile_label", tr("report-col-stockpile"));
model->addColumn("TaskResult.volume", tr("report-col-volume"));
model->addColumn("event_created", tr("report-col-created"));
table_view->setModel(model);
addWidget(table_view);
对于报告选项卡:
- 由于测试,这仍然充满了神奇的数字
- 我尝试过实现和不实现 rowCount 和 columnCount
声明是: 类 ReportTableModel : public Wt::Dbo::QueryModel
ReportTableModel::ReportTableModel(int rows, Wt::WObject *parent)
: QueryModel(parent),
rows_(rows),
columns_(7) // TODO clean this magic number up
{ }
boost::any ReportTableModel::data(const Wt::WModelIndex& index, int role) const {
if (index.column() < 5)
return QueryModel::data(index, role);
else {
// ...
return boost::any();
}
}
int ReportTableModel::rowCount(const Wt::WModelIndex& parent) const {
if (!parent.isValid())
return rows_;
else
return 0;
}
int ReportTableModel::columnCount(const Wt::WModelIndex& parent) const {
if (!parent.isValid())
return columns_;
else
return 0;
}
boost::any ReportTableModel::headerData(int section,
Wt::Orientation orientation,
int role) const
{
if (section <= 5) {
return QueryModel::headerData(section, orientation, role);
} else {
// ...
}
}
2015 年 4 月 16 日更新
我做了一个测试用例来说明这个问题,在其中我删除了引导程序,所有容器(所以现在我有 WApplication -> WContainer -> WTableView),但问题仍然存在。
【问题讨论】:
标签: wt