Search code examples
wt

Wt WTableView defaulting to pagination rather than virtual scroll


(Cross posted here - with code sample)

I've implemented the WTableView in my project, but it defaults to using paginating buttons rather than using virtual scroll (and does it in a very ugly way.) Even when I implemented the example almost exactly as shown in the example gallery, it still did this.

I'm in the process of setting up a standalone example, but essentially I have the following container hierarchy:

WApplication -> WTemplate -> WTabWidget -> ReportTab

ReportTab is the widget that I'd like to contain a table. I've attempted making it a WContainerWidget and a WTemplate, this made no difference.

Using the QueryModel<> directly vs my own implementation extending the QueryModel (mostly based on the VirtualModel) also made no real difference.

From what I read, the WTableView should only implement paging when the browser doesn't support JS. But my issue occurs over all browsers I've tried.

Code sample:

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);

For ReportTab:

  • because of testing, this is still full of magic numbers
  • I've tried with and without implementing the rowCount and columnCount

The declaration is: class 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 {
        // ...
    }
}

UPDATE April 16,2015

I made a test case to illustrate the issue, in it I removed bootstrap, all the containers (so now I have WApplication -> WContainer -> WTableView), but the problem persists.


Solution

  • Issue was that I had progressive-bootstrap enabled, which is incompatible with WTableView's ability to perform a virtual scroll. (well, real issue is that this isn't documented anywhere...)