1313use Ajax \semantic \html \base \constants \Direction ;
1414use Ajax \service \JArray ;
1515use Ajax \semantic \widgets \base \FieldAsTrait ;
16+ use Ajax \semantic \html \base \HtmlSemDoubleElement ;
1617
1718/**
1819 * DataTable widget for displaying list of objects
@@ -94,6 +95,7 @@ private function _generateContent($table){
9495 InstanceViewer::setIndex (0 );
9596 $ table ->fromDatabaseObjects ($ objects , function ($ instance ){
9697 $ this ->_instanceViewer ->setInstance ($ instance );
98+ InstanceViewer::$ index ++;
9799 $ result = $ this ->_instanceViewer ->getValues ();
98100 if ($ this ->_hasCheckboxes ){
99101 $ ck =new HtmlCheckbox ("ck- " .$ this ->identifier ,"" );
@@ -227,21 +229,25 @@ public function refresh($compileParts=["tbody"]){
227229 * @return callable
228230 */
229231 private function getFieldButtonCallable ($ caption ,$ callback =null ){
230- return $ this ->getCallable ($ this -> getFieldButton ( $ caption) ,$ callback );
232+ return $ this ->getCallable (" getFieldButton " ,[ $ caption] ,$ callback );
231233 }
232234
233235 /**
234236 * @param mixed $object
235237 * @param callable $callback
236238 * @return callable
237239 */
238- private function getCallable ($ object ,$ callback =null ){
239- $ result =function ($ instance ) use ($ object ,$ callback ){
240+ private function getCallable ($ thisCallback ,$ parameters ,$ callback =null ){
241+ $ result =function ($ instance ) use ($ thisCallback ,$ parameters ,$ callback ){
242+ $ object =call_user_func_array (array ($ this ,$ thisCallback ), $ parameters );
240243 if (isset ($ callback )){
241244 if (\is_callable ($ callback )){
242245 $ callback ($ object ,$ instance );
243246 }
244247 }
248+ if ($ object instanceof HtmlSemDoubleElement){
249+ $ object ->setProperty ("data-ajax " ,$ this ->_instanceViewer ->getIdentifier ());
250+ }
245251 return $ object ;
246252 };
247253 return $ result ;
@@ -252,9 +258,7 @@ private function getCallable($object,$callback=null){
252258 * @return HtmlButton
253259 */
254260 private function getFieldButton ($ caption ){
255- $ bt =new HtmlButton ("" ,$ caption );
256- $ bt ->setProperty ("data-ajax " ,$ this ->_instanceViewer ->getIdentifier ());
257- return $ bt ;
261+ return new HtmlButton ("" ,$ caption );
258262 }
259263
260264 /**
@@ -264,7 +268,7 @@ private function getFieldButton($caption){
264268 * @return \Ajax\semantic\widgets\datatable\DataTable
265269 */
266270 public function addFieldButton ($ caption ,$ callback =null ){
267- $ this ->addField ($ this ->getFieldButtonCallable ( $ caption ,$ callback ));
271+ $ this ->addField ($ this ->getCallable ( " getFieldButton " ,[ $ caption] ,$ callback ));
268272 return $ this ;
269273 }
270274
@@ -293,14 +297,12 @@ public function insertInFieldButton($index,$caption,$callback=null){
293297 }
294298
295299 private function addDefaultButton ($ icon ,$ class =null ,$ callback =null ){
296- $ bt =$ this ->getDefaultButton ($ icon ,$ class );
297- $ this ->addField ($ this ->getCallable ($ bt ,$ callback ));
300+ $ this ->addField ($ this ->getCallable ("getDefaultButton " ,[$ icon ,$ class ],$ callback ));
298301 return $ this ;
299302 }
300303
301304 private function insertDefaultButtonIn ($ index ,$ icon ,$ class =null ,$ callback =null ){
302- $ bt =$ this ->getDefaultButton ($ icon ,$ class );
303- $ this ->insertInField ($ index ,$ this ->getCallable ($ bt ,$ callback ));
305+ $ this ->insertInField ($ index ,$ this ->getCallable ("getDefaultButton " ,[$ icon ,$ class ],$ callback ));
304306 return $ this ;
305307 }
306308
@@ -399,4 +401,15 @@ public function setSortable($colIndex=NULL) {
399401 protected function _getFieldIdentifier ($ prefix ){
400402 return $ this ->identifier ."- {$ prefix }- " .$ this ->_instanceViewer ->getIdentifier ();
401403 }
404+
405+ /**
406+ * The callback function called after the insertion of each row when fromDatabaseObjects is called
407+ * callback function takes the parameters $row : the row inserted and $object: the instance of model used
408+ * @param callable $callback
409+ * @return DataTable
410+ */
411+ public function onNewRow ($ callback ) {
412+ $ this ->content ["table " ]->onNewRow ($ callback );
413+ return $ this ;
414+ }
402415}
0 commit comments