paging for tables

This commit is contained in:
Peter Schojer
2008-10-01 06:19:09 +00:00
parent 2045597f3f
commit 00b1f3cde5
21 changed files with 349 additions and 12 deletions

View File

@@ -78,6 +78,8 @@ public:
static const std::string EV_CELLSELECTED;
static const std::string EV_STARTCELLVALUECHANGE;
static const std::string HIDDEN_INDEX_ROW;
static const std::string FIELD_TOTALPROPERTY;
static const std::string FIELD_ROOT;
TableRenderer();
/// Creates the TableRenderer.

View File

@@ -177,18 +177,24 @@ protected:
Form::Ptr pForm = new Form("form1", Poco::URI("/"));
//pForm->setURL(...);
Table::TableColumns tc;
tc.push_back(new TableColumn(new TextFieldCell(0), "StaticText", 200 ));
tc.push_back(new TableColumn(new CheckButtonCell(0, "lbl", true), "CheckButton", 100));
tc.push_back(new TableColumn(new TextFieldCell(0), "StaticText", 200,true ));
tc.push_back(new TableColumn(new CheckButtonCell(0, "lbl", true), "CheckButton", 100, true));
Table::Ptr pTable = new Table(tc, new SimpleTableModel(2));
///init simpletablemodel
pTable->setValue(std::string("one"), 0,0);
pTable->setValue(std::string("two"), 1,0);
pTable->setValue(std::string("three"), 2,0);
pTable->setValue(std::string("four"), 3,0);
pTable->setValue(std::string("five"), 4,0);
pTable->setValue(true, 0,1);
pTable->setValue(false, 1,1);
pTable->setValue(true, 2,1);
pTable->setValue(false, 3,1);
pTable->setValue(true, 4,1);
pTable->setWidth(310);
pTable->setHeight(200);
pTable->setPaging(2);
pForm->add(new TextField("txtfield"));
CheckButton::Ptr ptrCheck2(new CheckButton("checkbutton", "CheckButton", false));

View File

@@ -35,6 +35,8 @@
#include "Poco/WebWidgets/ExtJS/ArrayTableSerializer.h"
#include "Poco/WebWidgets/ExtJS/TableRenderer.h"
#include "Poco/WebWidgets/ExtJS/Utility.h"
#include "Poco/WebWidgets/Table.h"
#include "Poco/DateTime.h"
@@ -53,7 +55,8 @@ void ArrayTableSerializer::serialize(std::ostream& ostr, const Table* pTable, st
// render the row-index as last column
const TableModel& tm = pTable->getModel();
const Table::TableColumns& tc = pTable->getColumns();
if (rowCntUser == 0 && pTable->getPagingSize() > 0)
rowCntUser = pTable->getPagingSize();
poco_assert_dbg (tc.size() == tm.getColumnCount());
std::size_t colCnt = tm.getColumnCount();
@@ -62,10 +65,11 @@ void ArrayTableSerializer::serialize(std::ostream& ostr, const Table* pTable, st
rowBegin = 0;
if ((rowCntUser > 0) && (rowBegin + rowCntUser < rowCnt))
rowCnt = rowBegin + rowCntUser;
ostr << "[";
ostr << "{\"" << TableRenderer::FIELD_TOTALPROPERTY << "\":\"" << tm.getRowCount() << "\",";
ostr << "\"" << TableRenderer::FIELD_ROOT << "\":[";
for (std::size_t row = rowBegin; row < rowCnt; ++row)
{
if (row != 0)
if (row != rowBegin)
ostr << ",[";
else
ostr << "[";
@@ -88,7 +92,7 @@ void ArrayTableSerializer::serialize(std::ostream& ostr, const Table* pTable, st
bool isString = (typeid(std::string) == aVal.type());
Cell::Ptr ptrCell = tc[col]->getCell();
if (isString)
ostr << "'" << RefAnyCast<std::string>(aVal) << "'";
ostr << "'" << Utility::safe(RefAnyCast<std::string>(aVal)) << "'";
else if (ptrCell)
{
//date must be written as string
@@ -105,7 +109,7 @@ void ArrayTableSerializer::serialize(std::ostream& ostr, const Table* pTable, st
ostr << "," << row;
ostr << "]";
}
ostr << "]";
ostr << "]}";
}

View File

@@ -70,6 +70,8 @@ const std::string TableRenderer::EV_KEYPRESSED("keypress");
const std::string TableRenderer::EV_ROWSELECTED("rowselect");
const std::string TableRenderer::EV_CELLSELECTED("cellselect");
const std::string TableRenderer::HIDDEN_INDEX_ROW("hidIdx");
const std::string TableRenderer::FIELD_TOTALPROPERTY("tp");
const std::string TableRenderer::FIELD_ROOT("data");
TableRenderer::TableRenderer()
@@ -516,7 +518,6 @@ void TableRenderer::renderProperties(const Table* pTable, const RenderContext& c
// })
if (pTable->getPagingSize() > 0)
{
ostr << ",remoteSort:true";
ostr << ",bbar:new Ext.PagingToolbar({";
ostr << "pageSize:" << pTable->getPagingSize() << ",";
ostr << "displayInfo:true,";
@@ -649,17 +650,19 @@ void TableRenderer::renderStore(const Table* pTable, std::ostream& ostr)
ostr << "proxy:new Ext.data.HttpProxy({url:";
std::map<std::string, std::string> addParams;
addParams.insert(std::make_pair(RequestHandler::KEY_EVID,Table::EV_LOADDATA));
std::string url(Utility::createURI(addParams, pTable->id()));
ostr << url << "}),";
ostr << "reader:new Ext.data.ArrayReader()";
ostr << "reader:new Ext.data.ArrayReader({totalCnt:'";
ostr << FIELD_TOTALPROPERTY << "',data:'" << FIELD_ROOT << "'})";
if (pTable->afterLoad.hasJavaScriptCode())
{
ostr << ",listeners:{";
Utility::writeJSEvent(ostr, EV_AFTERLOAD, pTable->afterLoad, &TableRenderer::createAfterLoadServerCallback, pTable);
ostr << "}";
}
if (pTable->getPagingSize() > 0)
ostr << ",remoteSort:true";
ostr << "})";
}

View File

@@ -1,4 +1,41 @@
Ext.override(Ext.data.ArrayReader, {
read : function(response){
var data = response.responseText;
var o = eval("("+data+")");
return this.readRecords(o);
},
readRecords : function(o){
var sid = this.meta ? this.meta.id : null;
var s = this.meta;
var recordType = this.recordType, fields = recordType.prototype.fields;
var records = [];
var root = o["data"];
var totalRecords = o["tp"];
for(var i = 0; i < root.length; i++){
var n = root[i];
var values = {};
var id = ((sid || sid === 0) && n[sid] !== undefined && n[sid] !== "" ? n[sid] : null);
for(var j = 0, jlen = fields.length; j < jlen; j++){
var f = fields.items[j];
var k = f.mapping !== undefined && f.mapping !== null ? f.mapping : j;
var v = n[k] !== undefined ? n[k] : f.defaultValue;
v = f.convert(v, n);
values[f.name] = v;
}
var record = new recordType(values, id);
record.json = n;
records[records.length] = record;
}
return {
success : true,
records : records,
totalRecords : totalRecords
};
}
});
Ext.grid.AppinfTable = Ext.extend(Ext.grid.EditorGridPanel, {
/**
* @cfg {Boolean} autoEdit