Is it possible to class method instead of function to event

I usually use

function my_beforeRend($dataItem){
}
$grid->event->attach('beforeRender', 'my_beforeRend');

My situation is below:

class MyClass{
  function my_beforeRender($dataItem){
  }
  function disp(){
    ...
    $grid->event->attach('beforeRender','MyClass.mybeforeRender'); // how to set 2nd parameter
  }
}

Thanks in advance.

It is the same format as used by call_user_func

php.net/manual/en/function.call-user-func.php

call_user_func(array($classname, ‘say_hello’));
call_user_func($classname .’::say_hello’); // As of 5.2.3

//prior PHP 5.23
$grid->event->attach('beforeRender',array('MyClass', 'mybeforeRender'));
//PHP 5.2.3 and later
$grid->event->attach('beforeRender','MyClass::mybeforeRender');

It works now.
Thanks Stanislav.

Can I pass one more or more arguments than the default individual $dataItem into the method?
Thanks

Nope, you can’t change that.
If you are using a method of the class, you can store some extra value as property of a class object. So code will be able to access it from the event handler.

I also hope to store properties in the class object but failed. It seems that the DhxGrid attached the method ahead of the PageGrid# object creation, so it only can use the static variables.
In my situation, I hope the following php code:

abstract class absClass{
protected $id;
public function __construct($id){
$this->id=$id;
}
public function id(){
return $this->id;
}
public function display(){
$grid = new \GridConnector($this->conn(),‘MySQLi’);
$grid->set_config($this->get_config());
$grid->event_attach(‘beforeRender’,[’\PageGrid’.$this->id(),‘my_beforeRender’]);
$grid->render_table($this->tablename(),$this->idname(),$this->fields(),$this->extra());
}
abstract public function my_beforeRender(\GridDataItem $dataItem);
}

class PageGrid1 extends absClass{
__
public function my_beforeRender(\GridDataItem $dataitem){
$imgpath = path($this->id()); ///// NOTICE: I cannot access $this->id() because id is not initialized.
$dataItem->set_value(‘image’,$imgpath);
}
}

Above code does not work, so I now changed to the following which I’m not intended to:

abstract class absClass{
// the same as above definition, except for changing my_beforeRender to static
abstract static function my_beforeRender(\GridDataItem $dataitem);
}
class PageGrid1 extends absClass{
static $idd=1;
public function __construct(){
parent::__construct(self::$idd);
}
public function my_beforeRender(\GridDataItem $dataitem){
$imgpath = path(self::$idd); //
$dataItem->set_value(‘image’,$imgpath);
}
}

Try to change

$grid->event_attach('beforeRender',['\PageGrid'.$this->id(),'my_beforeRender']);

to the

$grid->event_attach('beforeRender',[$this,'my_beforeRender']);

Change first parameter from name of class to the class instance.

It’s so great.
Thanks Stanislav!