leandrogehlen / yii2-treegrid Goto Github PK
View Code? Open in Web Editor NEWExtension for Yii2 Framework to work with jQuery TreeGrid
Extension for Yii2 Framework to work with jQuery TreeGrid
Hello,
I'm looking for any option to export treegrid in PDF or Excel Format (Like Kartik Gridview Export).
Can't install with php composer.phar require --prefer-dist leandrogehlen/yii2-treegrid "*"
, get the following output:
>php composer.phar require --prefer-dist leandrogehlen/yii2-treegrid "*"
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Installation request for leandrogehlen/yii2-treegrid * -> satisfiable by leandrogehlen/yii2-treegrid[dev-master].
- leandrogehlen/yii2-treegrid dev-master requires bower-asset/jquery-treegrid 0.3.0 -> no matching package found.
Potential causes:
- A typo in the package name
- The package is not available in a stable-enough version according to your minimum-stability setting
see <https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion> for more details.
Read <https://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.
Installation failed, reverting ./composer.json to its original content.
May be it is related with dependency bower-asset/jquery-treegrid: 0.3.0
?
HI, your treegrid has a bug.
Not correct url provided for ActionColumn(grid) buttons like view, edit, delete, etc..
Reason:
You get key from dataProvided when list is not sorted and put them for sorted list.
How to fix:
TreeGrid.php:
Hi,
any plans to implement a partial load of a subtree? If you have a really big dataset, the functioallity might break?
Best Philipp
I need to show tree of subcategories.
In dataProvider I have all cats tree
I use params:
'dataProvider' => $dataProvider,
'keyColumnName' => 'id',
'parentColumnName' => 'parent_id',
'parentRootValue' => 2,
parentRootValue= 2 - ID of parent category I need to...
All subcats are showing in right order but expande/collapse and tree-view not working in this case...
Hi,
I setup such as for my TreeGrid:
<?= TreeGrid::widget([
'dataProvider' => $dataProvider,
//'filterModel' => $searchModel,
'keyColumnName' => 'id',
'parentColumnName' => 'parent_id',
'parentRootValue' => '0', //first parentId value
'pluginOptions' => [
'initialState' => 'expanded',
],
'columns' => [
//['class' => 'yii\grid\SerialColumn'],
'title',
'alias',
[
'attribute' => 'language',
'label' => Yii::t('backend', 'Language'),
//'filter' => \backend\models\enums\BackendEnum::getLang(),
'value' => function($model){
return \backend\models\enums\BackendEnum::getLangByCode($model->language);
}
],
[
'attribute' => 'actived',
'label' => Yii::t('backend', 'Status'),
//'filter' => \backend\models\enums\BackendEnum::labelStatus(),
'value' => function($model) {
return $model->actived ? Yii::t('backend', 'Publish') : Yii::t('backend', 'Unpublish');
}
],
[
'class' => 'yii\grid\ActionColumn',
'template' => '{update}{delete}',
],
],
]); ?>
But I found that, the ID on {update} and {delete} url was wrong, such as: the row model ID is 10, but the url for updating is "update?id=9".
I temporary fix that issue by add urlCreator to ActionColumn:
'urlCreator' => function ($action, $model, $key, $index) { if ($action === 'update') { $url = yii\helpers\Url::to(['update', 'id' => $model->id]); return $url; } if ($action === 'delete') { $url = yii\helpers\Url::to(['delete', 'id' => $model->id]); return $url; } }
The problem:
If the values of keyColumnName
and parentColumnName
fields are strings with only numeric character, the recursivity of normalizeData
method in TreeGrid class is potentially endless.
Example case:
For example, if we have the follow data (informal code):
Node1: [key = "1", parentKey = null]
Node2: [key = "01", parentKey = "1"]
Node3: [key = "001", parentKey = "01"]
When is searching then Node2's children (value of $parentId parameter is "01"
), because Node2's parentKey is "1"
, the condition ArrayHelper::getValue($element, $this->parentColumnName) == $parentId
is evaluated true, therefore a new call to normalizeData
is thrown to search (again) the Node2's children.
Suggested modification:
Use the type-strict comparation operator (===) instead the double equal operator (==).
ArrayHelper::getValue($element, $this->parentColumnName) === $parentId
Hello,
I just want to get the result from another column and put it into next column for calculation and to save execution time.
example:
echo TreeGrid::widget([
'dataProvider' => $dataProvider,
'keyColumnName' => 'id',
'parentColumnName' => 'PARENT_ID',
'parentRootValue' => '', //first parentId value
'pluginOptions' => [
'initialState' => 'expanded', //collapsed
],
'columns' => [
[
'attribute' => 'JAN',
'value' => function($model, $key, $index, $grid){
$model['MONTH'] = 1;
$resultJan = $model->bALANCE;
return $resultJan;
},
],
[
'attribute' => 'FEB',
'value' => function($model, $key, $index, $grid) use ($resultJan){
$model['MONTH'] = 2;
return $resultJan+$model->bALANCE;
},
],
]
]);
So, Here I want to use $resultJan into FEB column.
I think it might be good to include the 'jquery.cookie.js' dependency in the TreeGridAssetBundle, in case someone wants to use the 'saveState' option for the treegrid plugin.
PHP 7.2
PHP Compile Error โ yii\base\ErrorException
Cannot use yii\base\Object as Object because 'Object' is a special class name
When generating a tree, in which more than 20 elements necessary pagination. It is not provided?
in yii\data\Pagination
property defaultPageSize = 20
filter model does not work
Help me
When comparing parent IDs the function normalizeData()
uses loose comparison:
if ($element[$this->parentColumnName] == $parentId) { [...] }
This can result in false positives (which ultimately can lead to recursive hierarchies, i.e. infinite loops during code execution).
Example:
$element[$this->parentColumnName] = 0; // int(0)
$parentId = 'p1'; // string(2) "p1"
$element[$this->parentColumnName] == $parentId // true
Using strict comparison will prevent this behaviour:
if ($element[$this->parentColumnName] === $parentId) { [...] }
Example:
$element[$this->parentColumnName] = 0; // int(0)
$parentId = 'p1'; // string(2) "p1"
$element[$this->parentColumnName] === $parentId // false
It cost me about four days to figure this out. D'oh! ๐ฃ
How i can add event on click on tree
Hi! Tell me please, How I can add filterModel and columns filter? Example, in GridView
'filterModel' => $searchModel,for column:
[
'attribute'=>'articles_id',
'format' => 'html',
'value' => function($data){
if (!empty ($data->article))
return $data->article->title;
},
'filter' => \common\models\ArticlesComments::getArticlesList()
],`
I'm having an issue with the grouping.
One level deep nest / groups properly
If it's deeper than one level it isn't nesting the child elements under the proper parent attribute. However, the open and close toggle icon, opens and closes the correct elements event though they aren't in the right location on the grid. I don't know if it's because the PK and Parent fields are strings and not integers.
Here is my exact config
TreeGrid::widget([
'dataProvider' => $dataProvider,
'keyColumnName' => 'id',
'parentColumnName' => 'p_id',
'pluginOptions' => [
'initialState' => 'collapsed',
'saveState' => true,
'saveStateName' => 'locations-list-state'
],
'columns' => [
'name',
'id',
'p_id'
],
]);
Hi, I am implementing "zoom-in" and zoom-out actions with TreeGrid widget, and have a problem with properly rendering TreeGrid when I zoom in to the level when parentRootValue is not 0.
The zoom-in action is defined in controller as follows:
public function actionZoomin($id)
{
$branch_ids = Tgstep::getBranch($id); // getBranch returns the ids of this element and all children
$query = Tgstep::find(['is_deleted'=>false])->where(['id'=>$branch_ids]);
$model = $this->findModel($id);
$dataProvider = new ActiveDataProvider([
'query' => $query,
'pagination' => false,
'sort' => [
'defaultOrder' => [
'parent_id' => SORT_ASC,
'position' => SORT_ASC,
]
],
]);
return $this->render('zoom', [
'dataProvider' => $dataProvider,
'root_id' => $model->parent_id,
]);
}
The corresponding view is as follows:
echo TreeGrid::widget([
'dataProvider' => $dataProvider,
'keyColumnName' => 'id',
'parentColumnName' => 'parent_id',
'parentRootValue' => $root_id,
'pluginOptions' => [
// zoom-in doesn't work if 'initialState' is not 'expanded'!
'initialState' => 'expanded',
'expanderExpandedClass' => 'glyphicon glyphicon-chevron-down',
'expanderCollapsedClass' => 'glyphicon glyphicon-chevron-right',
],
'columns' => [
'step_name',
'parent_id',
'id',
[
'class' => 'yii\grid\ActionColumn',
'template' => '{zoomin}',
'buttons' => [
'zoomin' => function ($url) {
return Html::a('<span class="glyphicon glyphicon-zoom-in"></span>',
$url, [
'title' => 'zoomin',
'data-pjax' => '0',
]);
}],
'urlCreator' => function ($action, $model, $key, $index) {
if ($action === 'zoomin') {
$url = Url::toRoute(['tgstep/zoomin', 'id' => $model->id]);
return $url;
}
}
]
]
]);
?>
The zoom-in works as I expect it. That is, when I click zoom-in in the action column, the TreeGrid is reduced to the element and all its children. But the hierarchy and indentation are shown in TreeGrid only for the top level elements (i.e. only those elements with parent_id = 0).
Is there a way to fix this? Thanks very much in advance for help.
@leandrogehlen following is my table structure.
CREATE TABLE IF NOT EXISTS category
(
id
int(255) NOT NULL AUTO_INCREMENT,
title
varchar(255) DEFAULT NULL,
image
varchar(100) DEFAULT NULL,
description
varchar(55) DEFAULT NULL,
parent_id
int(11) NOT NULL,
status
int(11) NOT NULL,
PRIMARY KEY (id
),
KEY fk_parent_id
(parent_id
)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=150 ;
can you please let me know whats wrong in it because I've updated my your extension in local four days ago. When I use your comparison "===" it gives me "no result" than I removed one = sign from it and got results but grouping is not well. As parent id 1 has many childs and extension results showed nothing
Please help me on this !!!
I am trying to use the extension with multi-levels categories but it is only show two levels
After upgrading to php7.2 occurs the error : "PHP message: PHP Fatal error: Cannot use yii\base\Object as Object because 'Object' is a special class name in /var/ww
w/html/my.site/vendor/leandrogehlen/yii2-treegrid/TreeColumn.php on line 8"
How to use with $searchModel filter ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.