1: <?php
2: require_once('../qcubed.inc.php');
3:
4: class PaginatorForm extends QForm {
5:
6: protected $dtg;
7:
8: protected $txtCount;
9:
10: protected $txtPageSize;
11:
12: protected function Form_Create() {
13: $this->dtg = new QDataGrid($this);
14: $this->dtg->SetDataBinder("dtg_Bind");
15: $this->dtg->Paginator = new QPaginator($this->dtg);
16: $this->dtg->CreateIndexedColumn("Item", 0);
17:
18: $this->txtCount = new QIntegerTextBox($this);
19: $this->txtCount->Name = "Count";
20: $this->txtCount->SaveState = true;
21: $this->txtCount->AddAction(new QChangeEvent(), new QAjaxAction("refreshGrid"));
22:
23: $this->txtPageSize = new QIntegerTextBox($this);
24: $this->txtPageSize->Name = "Page Size";
25: $this->txtPageSize->Text = 10;
26: $this->txtPageSize->SaveState = true;
27: $this->txtPageSize->AddAction(new QChangeEvent(), new QAjaxAction("refreshGrid"));
28:
29: $intPageSize = (int)$this->txtPageSize->Text;
30: $this->dtg->ItemsPerPage = $intPageSize;
31:
32: }
33:
34: protected function refreshGrid() {
35: $this->dtg->Refresh();
36: }
37:
38: public function dtg_Bind() {
39: $intPageSize = (int)$this->txtPageSize->Text;
40: $this->dtg->ItemsPerPage = $intPageSize;
41: $intCount = (int)$this->txtCount->Text;
42: $this->dtg->TotalItemCount = $intCount;
43: $intStart = $this->dtg->ItemsOffset;
44: $intEnd = min($intCount, $intStart + $intPageSize);
45: for ($i = $intStart; $i < $intEnd; $i++) {
46: $a[] = [self::NumToWord($i)];
47: }
48: if (!empty($a)) {
49: $this->dtg->DataSource = $a;
50: }
51: }
52:
53: protected static function NumToWord($intNum) {
54: $c = chr($intNum % 26 + 65);
55: $intNewNum = (int)floor($intNum / 26);
56: if ($intNewNum) {
57: $c = self::NumToWord($intNewNum) . $c;
58: }
59: return $c;
60: }
61:
62: }
63: PaginatorForm::Run('PaginatorForm');
64: ?>