@@ -30,6 +30,7 @@ class DataTable extends Widget {
3030 protected $ _editBehavior ;
3131 protected $ _visibleHover =false ;
3232 protected $ _targetSelector ;
33+ protected $ _refreshSelector ;
3334
3435
3536 public function __construct ($ identifier ,$ model ,$ modelInstance =NULL ) {
@@ -145,7 +146,7 @@ private function _generatePagination($table){
145146 $ menu ->setActiveItem ($ this ->_pagination ->getPage ()-1 );
146147 $ footer ->setValues ($ menu );
147148 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 " ]);
149150 }
150151
151152 protected function _getFieldName ($ index ){
@@ -177,7 +178,7 @@ protected function _setToolbarPosition($table,$captions=NULL){
177178 * The $callback function can take the following arguments : $field=>the compiled field, $instance : the active instance of the object, $index: the field position
178179 * @param int $index postion of the compiled field
179180 * @param callable $callback function called after the field compilation
180- * @return \Ajax\semantic\widgets\datatable\ DataTable
181+ * @return DataTable
181182 */
182183 public function afterCompile ($ index ,$ callback ){
183184 $ this ->_instanceViewer ->afterCompile ($ index ,$ callback );
@@ -206,7 +207,7 @@ public function getUrls() {
206207 /**
207208 * Sets the associative array of urls for refreshing, updating or deleting
208209 * @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
210211 */
211212 public function setUrls ($ urls ) {
212213 if (\is_array ($ urls )){
@@ -222,16 +223,28 @@ public function setUrls($urls) {
222223 /**
223224 * Paginates the DataTable element with a Semantic HtmlPaginationMenu component
224225 * @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
228229 * @return DataTable
229230 */
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 ){
231232 $ this ->_pagination =new Pagination ($ items_per_page ,$ pages_visibles ,$ page ,$ total_rowcount );
232233 return $ this ;
233234 }
234235
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+
235248
236249
237250 /**
@@ -289,4 +302,16 @@ public function setTargetSelector($_targetSelector) {
289302 $ this ->_targetSelector =$ _targetSelector ;
290303 return $ this ;
291304 }
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+
292317}
0 commit comments