Skip to content

Commit c6edaba

Browse files
committed
non auto pagination for DataTable
1 parent 80faa7e commit c6edaba

File tree

5 files changed

+27
-8
lines changed

5 files changed

+27
-8
lines changed

Ajax/common/html/HtmlCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public function setProperties($properties){
156156
* Sets the values of a property for each item in the collection
157157
* @param string $property
158158
* @param array $values
159-
* @return \Ajax\common\html\HtmlCollection
159+
* @return HtmlCollection
160160
*/
161161
public function setPropertyValues($property,$values){
162162
$i=0;

Ajax/semantic/html/base/HtmlSemDoubleElement.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Ajax\semantic\html\base\constants\Direction;
1212
use Ajax\JsUtils;
1313
use Phalcon\Mvc\View;
14+
use Ajax\semantic\html\base\constants\Side;
1415

1516
/**
1617
* Base class for Semantic double elements
@@ -71,7 +72,7 @@ public function addLabel($label, $before=false, $icon=NULL) {
7172
return $labelO;
7273
}
7374

74-
public function attachLabel($label,$side,$direction=Direction::NONE,$icon=NULL){
75+
public function attachLabel($label,$side=Side::TOP,$direction=Direction::NONE,$icon=NULL){
7576
$label=$this->addLabel($label,true,$icon);
7677
$label->setAttached($side,$direction);
7778
return $this;

Ajax/semantic/html/modules/HtmlModal.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function addAction($action){
5656
if(\array_search($action, ["Okay","Yes"])!==false){
5757
$class="approve";
5858
}
59-
if(\array_search($action, ["Cancel","No"])!==false){
59+
if(\array_search($action, ["Close","Cancel","No"])!==false){
6060
$class="cancel";
6161
}
6262
$action=new HtmlButton("action-".$this->identifier,$action);

Ajax/semantic/widgets/datatable/DataTable.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,25 @@ public function setUrls($urls) {
219219
return $this;
220220
}
221221

222-
public function paginate($items_per_page=10,$page=1){
223-
$this->_pagination=new Pagination($items_per_page,4,$page);
222+
/**
223+
* Paginates the DataTable element with a Semantic HtmlPaginationMenu component
224+
* @param number $page the active page number
225+
* @param number $items_per_page
226+
* @param number $pages_visibles
227+
* @param number $total_rowcount
228+
* @return DataTable
229+
*/
230+
public function paginate($page=1,$items_per_page=10,$pages_visibles=4,$total_rowcount=null){
231+
$this->_pagination=new Pagination($items_per_page,$pages_visibles,$page,$total_rowcount);
232+
return $this;
224233
}
225234

226235

227236

237+
/**
238+
* @param array $compileParts
239+
* @return DataTable
240+
*/
228241
public function refresh($compileParts=["tbody"]){
229242
$this->_compileParts=$compileParts;
230243
return $this;

Ajax/semantic/widgets/datatable/Pagination.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,18 @@ class Pagination {
77
private $visible;
88
private $page_count;
99
private $pages_visibles;
10+
private $row_count;
1011

11-
public function __construct($items_per_page=10,$pages_visibles=4,$page=1){
12+
public function __construct($items_per_page=10,$pages_visibles=4,$page=1,$row_count=null){
1213
$this->items_per_page=$items_per_page;
1314
$this->page=$page;
1415
$this->pages_visibles=$pages_visibles;
1516
$this->visible=true;
17+
$this->row_count=$row_count;
1618
}
1719

1820
public function getObjects($objects){
21+
$auto=(!isset($this->row_count));
1922
$offset = ($this->page - 1) * $this->items_per_page;
2023
$os=$objects;
2124
if(!\is_array($os)){
@@ -25,7 +28,7 @@ public function getObjects($objects){
2528
}
2629
}
2730
$this->page_count = 0;
28-
$row_count=\sizeof($os);
31+
$row_count=($auto)?\sizeof($os):$this->row_count;
2932
if (0 === $row_count) {
3033
$this->visible=false;
3134
} else {
@@ -35,7 +38,9 @@ public function getObjects($objects){
3538
$this->page = 1;
3639
}
3740
}
38-
return array_slice($os, $offset,$this->items_per_page);
41+
if($auto)
42+
return array_slice($os, $offset,$this->items_per_page);
43+
return $os;
3944
}
4045

4146
public function getItemsPerPage() {

0 commit comments

Comments
 (0)