NullRefExcep / yii2-datatables

Yii2 Widget for DataTables jQuery plug-in
http://www.datatables.net/
MIT License
72 stars 46 forks source link

Bug in the last release #49

Closed coderovich closed 5 years ago

coderovich commented 5 years ago

After last update class DataTable starts throw exception: throw new InvalidConfigException(get_class($this) . '::$data must be set.');

ZAYEC77 commented 5 years ago

@coderovich please add the code of the widget usage.

coderovich commented 5 years ago

sure. it's the same as for 1.0.4 version: DataTable::widget([ 'data' => $provider->getModels(), 'tableOptions' => ['class' => 'table table-bordered table-striped dataTable'], "pageLength" => 25, 'autoWidth' => false, 'order' => [], 'columns' => [ 'name', 'en_name', 'offers', ], ], ]) ?>

ZAYEC77 commented 5 years ago

@coderovich could you provide all stack trace?

coderovich commented 5 years ago

yep: Error: Class 'nullref\datatable\InvalidConfigException' not found in ..\vendor\nullref\yii2-datatables\src\DataTableColumn.php:68 Stack trace:

0 ..\vendor\yiisoft\yii2\base\BaseObject.php(109): nullref\datatable\DataTableColumn->init()

1 [internal function]: yii\base\BaseObject->__construct(Array)

2 ..\vendor\yiisoft\yii2\di\Container.php(384): ReflectionClass->newInstanceArgs(Array)

3 ..\vendor\yiisoft\yii2\di\Container.php(156): yii\di\Container->build('nullref\datatab...', Array, Array)

4 ..\vendor\yiisoft\yii2\BaseYii.php(349): yii\di\Container->get('nullref\datatab...', Array, Array)

5 ..\vendor\nullref\yii2-datatables\src\DataTable.php(131): yii\BaseYii::createObject(Array)

6 ..\vendor\nullref\yii2-datatables\src\DataTable.php(106): nullref\datatable\DataTable->initColumns()

7 ..\vendor\yiisoft\yii2\base\BaseObject.php(109): nullref\datatable\DataTable->init()

8 [internal function]: yii\base\BaseObject->__construct(Array)

9 ..\vendor\yiisoft\yii2\di\Container.php(384): ReflectionClass->newInstanceArgs(Array)

10 ..\vendor\yiisoft\yii2\di\Container.php(156): yii\di\Container->build('nullref\datatab...', Array, Array)

11 ..\vendor\yiisoft\yii2\BaseYii.php(349): yii\di\Container->get('nullref\datatab...', Array, Array)

12 ..\vendor\yiisoft\yii2\base\Widget.php(137): yii\BaseYii::createObject(Array)

13 ..\views\view.php(106): yii\base\Widget::widget(Array)


but it trows because did't got $data...

ZAYEC77 commented 5 years ago

@coderovich Sorry, but I can't reproduce this issue at my local env. Please, try to run my demo project. The route to Datatables demo: /product/default/datatable. View file path: src/modules/product/views/default/datatable.php.

coderovich commented 5 years ago

i found the stumbling block. Error happens when column property has dynamic item rendered via callback without 'data' property :

'columns' => [
        [
            'title'  => 'Custom Column',
            'render' => new JsExpression('function render(data, type, row, meta ){
                                        return row["foo"];
                                    }'),
        ],
    ]
coderovich commented 5 years ago

so what's reason to require 'data' property in custom column? In case while this column - is concated string from mixed data and does not have an particular data-provider.

ZAYEC77 commented 5 years ago

@coderovich You are totally right, I don't even know why we miss this case before, sorry for that :( Please, try the latest version from dev-master. It should resolve this problem.

coderovich commented 5 years ago

everything is ok now. Thanx for fix and sorry for my long reply.

But i think that in the next major versions it would be more convenient to do new class e.g. "nullref\datatable\CustomColumn" where 'data' column will not be. Following this, you can return required 'data' attribute to DataTableColumn.

ZAYEC77 commented 5 years ago

If you think that it will be useful -- feel free to create PR.