@@ -30,6 +30,7 @@ class DataTable extends Widget {
30
30
protected $ _editBehavior ;
31
31
protected $ _visibleHover =false ;
32
32
protected $ _targetSelector ;
33
+ protected $ _refreshSelector ;
33
34
34
35
35
36
public function __construct ($ identifier ,$ model ,$ modelInstance =NULL ) {
@@ -145,7 +146,7 @@ private function _generatePagination($table){
145
146
$ menu ->setActiveItem ($ this ->_pagination ->getPage ()-1 );
146
147
$ footer ->setValues ($ menu );
147
148
if (isset ($ this ->_urls ["refresh " ]))
148
- $ menu ->postOnClick ($ this ->_urls ["refresh " ],"{'p':$(this).attr('data-page')} " ," # " . $ this ->identifier . " tbody " ,["preventDefault " =>false ,"jqueryDone " =>"replaceWith " ]);
149
+ $ menu ->postOnClick ($ this ->_urls ["refresh " ],"{'p':$(this).attr('data-page')} " ,$ this ->getRefreshSelector () ,["preventDefault " =>false ,"jqueryDone " =>"replaceWith " ]);
149
150
}
150
151
151
152
protected function _getFieldName ($ index ){
@@ -177,7 +178,7 @@ protected function _setToolbarPosition($table,$captions=NULL){
177
178
* The $callback function can take the following arguments : $field=>the compiled field, $instance : the active instance of the object, $index: the field position
178
179
* @param int $index postion of the compiled field
179
180
* @param callable $callback function called after the field compilation
180
- * @return \Ajax\semantic\widgets\datatable\ DataTable
181
+ * @return DataTable
181
182
*/
182
183
public function afterCompile ($ index ,$ callback ){
183
184
$ this ->_instanceViewer ->afterCompile ($ index ,$ callback );
@@ -206,7 +207,7 @@ public function getUrls() {
206
207
/**
207
208
* Sets the associative array of urls for refreshing, updating or deleting
208
209
* @param string|array $urls associative array with keys refresh: for refreshing with search field or pagination, edit : for updating a row, delete: for deleting a row
209
- * @return \Ajax\semantic\widgets\datatable\ DataTable
210
+ * @return DataTable
210
211
*/
211
212
public function setUrls ($ urls ) {
212
213
if (\is_array ($ urls )){
@@ -222,16 +223,28 @@ public function setUrls($urls) {
222
223
/**
223
224
* Paginates the DataTable element with a Semantic HtmlPaginationMenu component
224
225
* @param number $page the active page number
225
- * @param number $items_per_page
226
- * @param number $pages_visibles
227
- * @param number $total_rowcount
226
+ * @param number $total_rowcount the total number of items
227
+ * @param number $items_per_page The number of items per page
228
+ * @param number $pages_visibles The number of visible pages in the Pagination component
228
229
* @return DataTable
229
230
*/
230
- public function paginate ($ page= 1 , $ items_per_page =10 ,$ pages_visibles =4 , $ total_rowcount = null ){
231
+ public function paginate ($ page, $ total_rowcount , $ items_per_page =10 ,$ pages_visibles =4 ){
231
232
$ this ->_pagination =new Pagination ($ items_per_page ,$ pages_visibles ,$ page ,$ total_rowcount );
232
233
return $ this ;
233
234
}
234
235
236
+ /**
237
+ * Auto Paginates the DataTable element with a Semantic HtmlPaginationMenu component
238
+ * @param number $page the active page number
239
+ * @param number $items_per_page The number of items per page
240
+ * @param number $pages_visibles The number of visible pages in the Pagination component
241
+ * @return DataTable
242
+ */
243
+ public function autoPaginate ($ page =1 ,$ items_per_page =10 ,$ pages_visibles =4 ){
244
+ $ this ->_pagination =new Pagination ($ items_per_page ,$ pages_visibles ,$ page );
245
+ return $ this ;
246
+ }
247
+
235
248
236
249
237
250
/**
@@ -289,4 +302,16 @@ public function setTargetSelector($_targetSelector) {
289
302
$ this ->_targetSelector =$ _targetSelector ;
290
303
return $ this ;
291
304
}
305
+
306
+ public function getRefreshSelector () {
307
+ if (isset ($ this ->_refreshSelector ))
308
+ return $ this ->_refreshSelector ;
309
+ return "# " .$ this ->identifier ." tbody " ;
310
+ }
311
+
312
+ public function setRefreshSelector ($ _refreshSelector ) {
313
+ $ this ->_refreshSelector =$ _refreshSelector ;
314
+ return $ this ;
315
+ }
316
+
292
317
}
0 commit comments