This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

SerZH
SerZH

Hi, i'm trying to get Datatable widget work with my plugin but I can't catch 'data.getRecords' event. Please, help me. controller: public function construct() { parent::construct(); BackendMenu::setContext('Serzh.Drugs', 'drugs', 'pricechecker'); $config = [ 'dataSource' => 'server', 'columns' => [['title'=>'id'],['title'=>'drug'],['title'=>'man'],['title'=>'ToDrug'],['title'=>'ToForm']], ]; $table = new Table($this,$config); //$table->alias = ''; $table->bindToController(); } Plugin.php: public function boot() { Event::listen('data.getRecords', function ($offset,$total){ return [ ['id'=>1, 'drug'=>'John', 'man'=>'Smith'], ['id'=>2, 'drug'=>'John', 'man'=>'Doe'], ]; }); Event::listen('data.getCount', function (){ return 2; }); } index.htm <?= $this->widget->table->render() ?>

Last updated

DMeganoski
DMeganoski

You should use the 'pre' and 'code' tags to format your code, otherwise it makes it very hard to read. In fact, because you have it all in one line and your code contains a comment, my ide interpreted some of it as being commented out, though I don't think it all is.

Here is a cleanup, what I assume is your verison.

Controller:


public function construct() {
        parent::construct();
        BackendMenu::setContext('Serzh.Drugs', 'drugs', 'pricechecker');
        $config = [
            'dataSource' => 'server',
            'columns' => [
                ['title' => 'id'],
                ['title' => 'drug'],
                ['title' => 'man'],
                ['title' => 'ToDrug'],
                ['title' => 'ToForm']
            ],
        ];
        $table = new Table($this, $config);
        //$table->alias = '';
        $table->bindToController();
    }

Plugin.php:


 public function boot() {
        Event::listen('data.getRecords', function ($offset, $total) {
            return [['id' => 1, 'drug' => 'John', 'man' => 'Smith'], ['id' => 2, 'drug' => 'John', 'man' => 'Doe'],];
        });
        Event::listen('data.getCount', function () {
            return 2;
        });
    }

index.htm:


= $this->widget->table->render() ?>

You did not mention what exactly the issue is. I don't know if I have the knowledge to help you personally, but provided some more details might get you an answer faster.

Are you getting any error messages or is it just not showing up? Any information in your log files?

SerZH
SerZH

DMeganoski said:

You should use the 'pre' and 'code' tags to format your code, otherwise it makes it very hard to read. In fact, because you have it all in one line and your code contains a comment, my ide interpreted some of it as being commented out, though I don't think it all is.

Here is a cleanup, what I assume is your verison.

Controller:


public function construct() {
       parent::construct();
       BackendMenu::setContext('Serzh.Drugs', 'drugs', 'pricechecker');
       $config = [
           'dataSource' => 'server',
           'columns' => [
               ['title' => 'id'],
               ['title' => 'drug'],
               ['title' => 'man'],
               ['title' => 'ToDrug'],
               ['title' => 'ToForm']
           ],
       ];
       $table = new Table($this, $config);
       //$table->alias = '';
       $table->bindToController();
   }

Plugin.php:


public function boot() {
       Event::listen('data.getRecords', function ($offset, $total) {
           return [['id' => 1, 'drug' => 'John', 'man' => 'Smith'], ['id' => 2, 'drug' => 'John', 'man' => 'Doe'],];
       });
       Event::listen('data.getCount', function () {
           return 2;
       });
   }

index.htm:


= $this->widget->table->render() ?>

You did not mention what exactly the issue is. I don't know if I have the knowledge to help you personally, but provided some more details might get you an answer faster.

Are you getting any error messages or is it just not showing up? Any information in your log files?

Hi, thanks for reply. I get no errors with this code. Just nothing on controllers admin page. The problem is that i can't set this widget to recieve records data (Records data is not from the model).

P.S.: I need a widget/component that can work with different datasources.

Last updated

1-3 of 3

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.