mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-14 23:07:56 +02:00
added table selectionmodel, auto-mask tables while loading
This commit is contained in:
@@ -72,8 +72,16 @@ void TableRenderer::renderHead(const Renderable* pRenderable, const RenderContex
|
||||
poco_assert_dbg (pRenderable != 0);
|
||||
poco_assert_dbg (pRenderable->type() == typeid(Poco::WebWidgets::Table));
|
||||
const Table* pTable = static_cast<const Poco::WebWidgets::Table*>(pRenderable);
|
||||
|
||||
const Table::TableColumns& cols = pTable->getColumns();
|
||||
bool editable = false;
|
||||
for (Table::TableColumns::const_iterator it = cols.begin(); it != cols.end() && !editable; ++it)
|
||||
{
|
||||
editable |= (*it)->isEditable();
|
||||
}
|
||||
if (editable)
|
||||
ostr << "new Ext.grid.EditorGridPanel({";
|
||||
else
|
||||
ostr << "new Ext.grid.GridPanel({";
|
||||
|
||||
TableRenderer::renderProperties(pTable, context, ostr);
|
||||
|
||||
@@ -131,9 +139,16 @@ void TableRenderer::renderProperties(const Table* pTable, const RenderContext& c
|
||||
WebApplication& app = WebApplication::instance();
|
||||
Renderable::ID id = pTable->id();
|
||||
Utility::writeRenderableProperties(pTable, ostr);
|
||||
|
||||
const Table::TableColumns& cols = pTable->getColumns();
|
||||
bool editable = false;
|
||||
for (Table::TableColumns::const_iterator it = cols.begin(); it != cols.end() && !editable; ++it)
|
||||
{
|
||||
editable |= (*it)->isEditable();
|
||||
}
|
||||
ostr << ",listeners:{";
|
||||
bool written = Utility::writeJSEvent(ostr, EV_AFTEREDIT, pTable->cellValueChanged.jsDelegates());
|
||||
bool written = false;
|
||||
if (editable)
|
||||
written = Utility::writeJSEvent(ostr, EV_AFTEREDIT, pTable->cellValueChanged.jsDelegates());
|
||||
if (written)
|
||||
ostr << ",";
|
||||
|
||||
@@ -145,7 +160,9 @@ void TableRenderer::renderProperties(const Table* pTable, const RenderContext& c
|
||||
renderColumns(pTable, context, ostr);
|
||||
// forbid reordering of columns, otherwise col index will not match the col index at the server
|
||||
// sorting is allowed though, i.e row matching is active
|
||||
ostr << ",clicksToEdit:1,stripeRows:true,enableColumnHide:false,enableColumnMove:false";
|
||||
ostr << ",clicksToEdit:1,stripeRows:true,enableColumnHide:false,enableColumnMove:false,loadMask:true";
|
||||
if (pTable->getSelectionModel() == Table::SM_ROW)
|
||||
ostr << ",selModel:new Ext.grid.RowSelectionModel()";
|
||||
if (pTable->getWidth() > 0)
|
||||
ostr << ",width:" << pTable->getWidth();
|
||||
if (pTable->getHeight() > 0)
|
||||
|
@@ -56,7 +56,7 @@ namespace WebWidgets {
|
||||
|
||||
|
||||
class WebWidgets_API Table: public View, public RequestProcessor
|
||||
/// A Table widget.
|
||||
/// A Table widget. Uses per default single cell selection.
|
||||
{
|
||||
public:
|
||||
typedef Poco::AutoPtr<Table> Ptr;
|
||||
@@ -79,6 +79,7 @@ public:
|
||||
};
|
||||
|
||||
struct CellValueChange
|
||||
/// Data sent with a cellValueChanged event.
|
||||
{
|
||||
std::size_t row;
|
||||
std::size_t col;
|
||||
@@ -102,6 +103,14 @@ public:
|
||||
|
||||
FIFOEvent<LoadData> beforeLoad; /// thrown whenever a load is requested, internal event to which the TableRenderer must register
|
||||
|
||||
enum SelectionModel
|
||||
/// The selection model used for the table
|
||||
{
|
||||
SM_CELL = 0,
|
||||
SM_ROW
|
||||
};
|
||||
|
||||
|
||||
|
||||
Table(const TableColumns& tc, TableModel::Ptr pModel);
|
||||
/// Creates an anonymous Table.
|
||||
@@ -121,6 +130,12 @@ public:
|
||||
void setValue(const Poco::Any& val, std::size_t row, std::size_t col);
|
||||
/// Sets the value at pos(row, col)
|
||||
|
||||
void setSelectionModel(SelectionModel sm);
|
||||
/// Sets the selectionmodel.
|
||||
|
||||
SelectionModel getSelectionModel() const;
|
||||
/// Returns the selection model
|
||||
|
||||
void clear();
|
||||
/// Clears the content of the table
|
||||
|
||||
@@ -152,6 +167,7 @@ protected:
|
||||
private:
|
||||
TableModel::Ptr _pModel;
|
||||
TableColumns _columns;
|
||||
SelectionModel _sm;
|
||||
};
|
||||
|
||||
|
||||
@@ -194,6 +210,18 @@ inline const TableModel& Table::getModel() const
|
||||
}
|
||||
|
||||
|
||||
inline void Table::setSelectionModel(Table::SelectionModel sm)
|
||||
{
|
||||
_sm = sm;
|
||||
}
|
||||
|
||||
|
||||
inline Table::SelectionModel Table::getSelectionModel() const
|
||||
{
|
||||
return _sm;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::WebWidgets
|
||||
|
||||
|
||||
|
@@ -65,7 +65,6 @@ public:
|
||||
bool isSortable() const;
|
||||
/// Returns if the column is sortable
|
||||
|
||||
|
||||
void setSortable(bool val);
|
||||
/// Sets if the column is sortable
|
||||
|
||||
|
@@ -56,7 +56,8 @@ const std::string Table::EV_LOADDATA("load");
|
||||
Table::Table(const TableColumns& tc, TableModel::Ptr pModel):
|
||||
View(typeid(Table)),
|
||||
_pModel(pModel),
|
||||
_columns(tc)
|
||||
_columns(tc),
|
||||
_sm(SM_CELL)
|
||||
{
|
||||
checkValidConfig();
|
||||
}
|
||||
@@ -65,7 +66,8 @@ Table::Table(const TableColumns& tc, TableModel::Ptr pModel):
|
||||
Table::Table(const std::string& name, const TableColumns& tc, TableModel::Ptr pModel):
|
||||
View(name, typeid(Table)),
|
||||
_pModel(pModel),
|
||||
_columns(tc)
|
||||
_columns(tc),
|
||||
_sm(SM_CELL)
|
||||
{
|
||||
checkValidConfig();
|
||||
}
|
||||
@@ -74,7 +76,8 @@ Table::Table(const std::string& name, const TableColumns& tc, TableModel::Ptr pM
|
||||
Table::Table(const std::string& name, const std::type_info& type, const TableColumns& tc, TableModel::Ptr pModel):
|
||||
View(name, type),
|
||||
_pModel(pModel),
|
||||
_columns(tc)
|
||||
_columns(tc),
|
||||
_sm(SM_CELL)
|
||||
{
|
||||
checkValidConfig();
|
||||
}
|
||||
@@ -83,7 +86,8 @@ Table::Table(const std::string& name, const std::type_info& type, const TableCol
|
||||
Table::Table(const std::type_info& type, const TableColumns& tc, TableModel::Ptr pModel):
|
||||
View(type),
|
||||
_pModel(pModel),
|
||||
_columns(tc)
|
||||
_columns(tc),
|
||||
_sm(SM_CELL)
|
||||
{
|
||||
checkValidConfig();
|
||||
}
|
||||
@@ -147,6 +151,7 @@ void Table::handleAjaxRequest(const Poco::Net::NameValueCollection& args, Poco::
|
||||
{
|
||||
if (col < 0 || row < 0 || col >= getColumnCount())
|
||||
throw InvalidArgumentException("col/row out of range");
|
||||
|
||||
CellClick ev(row, col);
|
||||
cellClicked(this, ev);
|
||||
response.send();
|
||||
|
Reference in New Issue
Block a user