Project

General

Profile

WTableView - including WLink to allow "opening" of a selected item

Added by David Hubbard over 10 years ago

Hi

I'm looking to use the WTableView (with TableModel) to maintain data records in a database. On this I'm looking to show a summary of each objects attributes in columns of the table and then "launch" a full panel to allow all details to be edited.

So, is it possible to include a hyperlink [WLink?] (say in the first column of each row) which I can use to allow a user to select and open the new panel? I have had a look at WItemDelegate, but have deduced this is more about editing the cell data in situ rather than helping me.

If this is done in any of the examples then please just point me at it.

Regards

David


Replies (2)

RE: WTableView - including WLink to allow "opening" of a selected item - Added by Koen Deforche over 10 years ago

You should have your model return "LinkRole" data:

http://www.webtoolkit.eu/wt/doc/reference/html/group__modelview.html#ga0ae864e12320f9f89172735e075ed068

Tĥe standard item delegate will then render a link (WAnchor) for it.

RE: WTableView - including WLink to allow "opening" of a selected item - Added by David Hubbard over 10 years ago

Koen

Many thanks that's great - I get it now.

For the record (and others following) here's what I got working:

...in TableModel

public abstract class MyModel extends WAbstractTableModel {

    ...

    @Override
    public Object getData(final WModelIndex index, int role) {

        Object data = null;

        switch (role) {

            case ItemDataRole.DisplayRole:

                MyData md = (MyData)dataList.get(index.getRow());

                switch(index.getColumn()) {                    
                    case 0 :
                        data = new WString("{1}").arg(Long.toString(md.getId()));
                        break;
                    case 1 :
                        data = new WString("{1}").arg(md.getName());
                        break;

                    ...

                }
                break;

            case ItemDataRole.LinkRole:

                if (index.getColumn() == 0) {
                    data = new WLink("http://www.webtoolkit.eu/jwt/");
                }
                break;
        }
        return data;
    }

    ...
}
    (1-2/2)