Project

General

Profile

Actions

Support #5022

closed

WTableView Column headers

Added by Nicole King over 8 years ago. Updated over 8 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
Start date:
07/03/2016
Due date:
% Done:

0%

Estimated time:

Description

I'm sure this is the most trivial of questions, but I've searched long and hard without finding an answer.

I have the following model and view

class ScheduledTaskTableModel: public Wt::WStandardItemModel {
public:
    ScheduledTaskTableModel(std::list<ScheduledTask*> const &tasks, WObject* parent);

private:
    std::vector<ScheduledTask*> const tasks_;
};

class CronState: public Wt::WTableView {
public:
    CronState(Wt::WContainerWidget *parent);

private:
    ScheduledTaskTableModel *model_;
};

CronState::CronState(Wt::WContainerWidget *parent) :
        Wt::WTableView(parent), model_(
                new ScheduledTaskTableModel(DatabaseConnection::threadInstance()->load<ScheduledTask>(), this)) {
    setModel(model_);
    setSelectionMode(Wt::NoSelection);
    setSortingEnabled(0, true);
    setSortingEnabled(1, true);
    setColumnAlignment(2, Wt::AlignCenter);
    setAlternatingRowColors(true);
    setEditTriggers(Wt::WAbstractItemView::DoubleClicked);
    setEditOptions( Wt::WAbstractItemView::SingleEditor);
    setHeaderHeight(100);
}

ScheduledTaskTableModel::ScheduledTaskTableModel(std::list<ScheduledTask*> const &tasks, WObject* parent) :
        Wt::WStandardItemModel(parent), tasks_(tasks.begin(), tasks.end()) {
    for (ScheduledTask const *task : tasks_) {
        std::vector<Wt::WStandardItem *> items;
        items.emplace_back(new Wt::WStandardItem(task->get_name()));
        items.emplace_back(new Wt::WStandardItem(SmartEnumTraits<ScheduledTaskType>::toString(task->get_type())));
        items.emplace_back(new Wt::WStandardItem(std::to_string(task->get_enabled())));
        items.emplace_back(new Wt::WStandardItem(task->get_last_run().toStringForDisplay()));
        items.emplace_back(new Wt::WStandardItem(task->scheduleForDisplay()));
        appendRow(items);
    }
}

When displayed, I'd like to have headers on the different columns: "Name", "Type", "Enabled", "Last Run", "Schedule". I cannot find how to do this in the documentation, nor in any posted help requests here or on StackOverflow.

Could someone please tell me the answer to this, very simple, question?

Actions #1

Updated by Nicole King over 8 years ago

Answered it myself. It's not very clear from the documentation, but you use a call like this:

setHeaderData(0, Wt::Orientation::Horizontal, "Name", Wt::ItemDataRole::DisplayRole);
Actions #2

Updated by Wim Dumon over 8 years ago

  • Status changed from New to Closed
Actions

Also available in: Atom PDF