1414#include <Wt/WApplication>
1515#include <Wt/WDate>
1616#include <Wt/WEnvironment>
17+ #include <Wt/WItemDelegate>
1718#include <Wt/WStandardItemModel>
1819#include <Wt/WText>
1920
2021#include <Wt/WBorderLayout>
2122#include <Wt/WFitLayout>
2223
23- #include <Wt/Ext/Calendar>
24- #include <Wt/Ext/Container>
25- #include <Wt/Ext/DateField>
26- #include <Wt/Ext/LineEdit>
27- #include <Wt/Ext/NumberField>
28- #include <Wt/Ext/Panel>
29- #include <Wt/Ext/TableView>
24+ #include <Wt/WStandardItem>
25+ #include <Wt/WTableView>
3026
3127#include <Wt/Chart/WCartesianChart>
3228#include <Wt/Chart/WPieChart>
@@ -42,6 +38,11 @@ namespace {
4238
4339 if (f ) {
4440 readFromCsv (f , model );
41+
42+ for (int row = 0 ; row < model -> rowCount (); ++ row )
43+ for (int col = 0 ; col < model -> columnCount (); ++ col )
44+ model -> item (row , col )-> setFlags (ItemIsSelectable | ItemIsEditable );
45+
4546 return model ;
4647 } else {
4748 WString error (WString ::tr ("error-missing-data" ));
@@ -73,30 +74,45 @@ CategoryExample::CategoryExample(Wt::WContainerWidget *parent):
7374 if (!model )
7475 return ;
7576
76- /*
77- * If we have JavaScript, show an Ext table view that allows editing
78- * of the model.
79- */
80- if (wApp -> environment ().javaScript ()) {
81- WContainerWidget * w = new WContainerWidget (this );
82- Ext ::TableView * table = new Ext ::TableView (w );
83- table -> setMargin (10 , Top | Bottom );
84- table -> setMargin (WLength ::Auto , Left | Right );
85- table -> resize (500 , 175 );
86- table -> setModel (model );
87- table -> setAutoExpandColumn (0 );
88-
89- table -> setEditor (0 , new Ext ::LineEdit ());
90-
91- for (int i = 1 ; i < model -> columnCount (); ++ i ) {
92- Ext ::NumberField * nf = new Ext ::NumberField ();
93- table -> setEditor (i , nf );
94- }
77+ // Show a view that allows editing of the model.
78+ WContainerWidget * w = new WContainerWidget (this );
79+ WTableView * table = new WTableView (w );
80+
81+ table -> setMargin (10 , Top | Bottom );
82+ table -> setMargin (WLength ::Auto , Left | Right );
83+
84+ table -> setModel (model );
85+ table -> setSortingEnabled (true);
86+ table -> setColumnResizeEnabled (true);
87+ table -> setSelectionMode (NoSelection );
88+ table -> setAlternatingRowColors (true);
89+ table -> setColumnAlignment (0 , AlignCenter );
90+ table -> setHeaderAlignment (0 , AlignCenter );
91+ table -> setRowHeight (22 ); // height needed for line edit in IE
92+
93+ if (WApplication ::instance ()-> environment ().ajax ()) {
94+ table -> resize (600 , 20 + 5 * 22 );
95+ table -> setEditTriggers (WAbstractItemView ::SingleClicked );
96+ } else {
97+ table -> resize (600 , WLength ::Auto );
98+
99+ // Editing does not really work without Ajax, it would require an
100+ // additional button somewhere to confirm the edited value
101+ table -> setEditTriggers (WAbstractItemView ::NoEditTrigger );
95102 }
96103
104+ WItemDelegate * delegate = new WItemDelegate (this );
105+ delegate -> setTextFormat ("%.f" );
106+ table -> setItemDelegate (delegate );
107+
108+ table -> setColumnWidth (0 , 80 );
109+ for (int i = 1 ; i < model -> columnCount (); ++ i )
110+ table -> setColumnWidth (i , 120 );
111+
97112 /*
98113 * Create the category chart.
99114 */
115+
100116 WCartesianChart * chart = new WCartesianChart (this );
101117 chart -> setModel (model ); // set the model
102118 chart -> setXSeriesColumn (0 ); // set the column that holds the categories
@@ -235,23 +251,22 @@ PieExample::PieExample(WContainerWidget *parent):
235251 if (!model )
236252 return ;
237253
238- /*
239- * If we have JavaScript, show an Ext table view that allows editing
240- * of the model.
241- */
242- if (wApp -> environment ().javaScript ()) {
243- WContainerWidget * w = new WContainerWidget (this );
244- Ext ::TableView * table = new Ext ::TableView (w );
245- table -> setMargin (10 , Top | Bottom );
246- table -> setMargin (WLength ::Auto , Left | Right );
247- table -> resize (300 , 175 );
248- table -> setModel (model );
249- table -> setAutoExpandColumn (0 );
250-
251- table -> setEditor (0 , new Ext ::LineEdit ());
252-
253- for (int i = 1 ; i < model -> columnCount (); ++ i )
254- table -> setEditor (i , new Ext ::NumberField ());
254+ WContainerWidget * w = new WContainerWidget (this );
255+ WTableView * table = new WTableView (w );
256+
257+ table -> setMargin (10 , Top | Bottom );
258+ table -> setMargin (WLength ::Auto , Left | Right );
259+ table -> setSortingEnabled (true);
260+ table -> setModel (model );
261+ table -> setColumnWidth (1 , 100 );
262+ table -> setRowHeight (22 ); // height needed for line edit in IE
263+
264+ if (WApplication ::instance ()-> environment ().ajax ()) {
265+ table -> resize (150 + 100 + 14 , 20 + 6 * 22 );
266+ table -> setEditTriggers (WAbstractItemView ::SingleClicked );
267+ } else {
268+ table -> resize (150 + 100 + 14 , WLength ::Auto );
269+ table -> setEditTriggers (WAbstractItemView ::NoEditTrigger );
255270 }
256271
257272 /*
0 commit comments