Project

General

Profile

Sortable data in WTableView

Added by Axel Sjöberg about 4 years ago

Hello, I have been trying to get WTableView to work as shown in the widget gallery combined with the WStandardItemModel example. This is my current code:

int rows = 5;

int columns = 4;

std::shared_ptrWt::WStandardItemModel model =

std::make_sharedWt::WStandardItemModel(rows, columns);

model->setHeaderData(0, "1");

model->setHeaderData(0, "2");

model->setHeaderData(0, "3");

model->setHeaderData(0, "4");

for (int row = 0; row < rows; ++row) {

for (int column = 0; column < columns; ++column) {

auto item = std::make_uniqueWt::WStandardItem();

item->setText("Item " + std::to_string(row)

  • ", " + std::to_string(column));
    model->setItem(row, column, std::move(item));
    }
    }

tableView->setModel(model);

tableView->setAlternatingRowColors(true);

tableView->setColumnResizeEnabled(false);

tableView->setColumnAlignment(0, Wt::AlignmentFlag::Center);

tableView->setHeaderAlignment(0, Wt::AlignmentFlag::Center);

tableView->setAlternatingRowColors(true);

tableView->setRowHeight(28);

tableView->setHeaderHeight(28);

tableView->setSelectionMode(Wt::SelectionMode::Single);

tableView->setEditTriggers(Wt::EditTrigger::None);

const int WIDTH = 120;

for (int i = 0; i < tableView~~model()~~>columnCount(); ++i)

tableView->setColumnWidth(i, 120);

/*

  • 7 pixels are padding/border per column
  • 2 pixels are border of the entire table
    */
    tableView~~setWidth((WIDTH + 7) * tableView~~>model()->columnCount() + 2);

I attached a picture of what this results in. What am I missing? I'm using wt 4.1.0 (I did not see any bugfixes related to anything like this in the release notes)


Replies (3)

RE: Sortable data in WTableView - Added by Axel Sjöberg about 4 years ago

I attached the wrong picture, can I not remove it myself?

Here is what was supposed to be in the attachment.

RE: Sortable data in WTableView - Added by Roel Standaert about 4 years ago

So your table is showing up "naked", just the data, no headers or anything? It seems to me you're just missing the resources. From your previous posts it seems you're on Windows. Set the --resources-dir command line argument to point to Wt's resources folder (e.g. C:\Program Files\Wt...\lib\share\Wt\resources), or copy the resources folder to your --docroot.

I removed your first attachment.

RE: Sortable data in WTableView - Added by Axel Sjöberg about 4 years ago

Hello,

Thanks, my resources-dir was wrong.

But to my horror I realized that I can not select an item, and press ctrl + c to copy the cell's contents. I have set these flags for the tableView:

tableView->setSelectionBehavior(Wt::SelectionBehavior::Items);

tableView->setSelectionMode(Wt::SelectionMode::Single);

Is it possible to copy tableView cell contents into the clipboard? (As it is with Wt::WTtable)

    (1-3/3)