`
ipumpkin
  • 浏览: 6682 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

ux.maximgb.treegrid 使用指南

阅读更多
Tips for new users


Hi,

Having spent the last few days trying to get a hang of TreeGrid, I feel I should share some of what I've learnt for the benefit of new users who might come across this thread.

I have found this parts of this thread being slightly outdated (posts from 2 years ago), and TreeGrid in general could use better documentation. Hopefully this will help others:

Adjacency List vs. Nested Set Models

TreeGrid offers two types of stores:
•Adjacency List (AdjacencyListStore)
•Nested Set (NestedSetStore)
These models are, in principal, two SQL related strategies to represent hierarchy in databases.

TreeGrid ships with two corresponding examples (examples/server_al & examples/server_ns), although no use of SQL is demonstrated in these examples.

Adjacency List requires each record to contain the following fields:
•ID
•Parent ID
•Is Leaf

Nested Set requires - in addition to the fields above - the following fields:
•Lft
•Rgt
•Level
How Lft, Rgt, are calculated is explained below.

Which one should I choose?

Adjacency List is far more simple than the Nested Set model, as you don't have to calculate Lft and Rgt.

One example where this is important is when you plan to add records dynamically to TreeGrid - if you are using NestedSetStore, you'd have to calculate Lft and Rgt; with AdjacencyListStore, you only need to know the parent id.

So why would I choose Nested Set?

The hierarchy logic in databases can be implemented either by SQL queries or by a server-side script. For example, in order to find the top parent of a node, programmers might use SQL only, or a hybrid between SQL and PHP.

Nested Set makes life easier for those who implement the hierarchy logic via SQL queries. Then, if the database contains the lft and rgt fields anyway, you might just as well use the NestedSetStore with TreeGrid. If your database does not contain lft and rgt fields - you should probably use the AdjacencyListStore.

How do I calculate Lft and Rgt?

How Lft and Rgt are calculated is explained (alongside a thorough explanation of the two models) here: http://dev.mysql.com/tech-resources/...ical-data.html

However, TreeGrid ships with Tree.php script that can calculate them for you.

The following PHP script demonstrates how it is used:


 
  $tree = new Tree();  
      
    $result = sql("SELECT * FROM nodes");

    while ($node = mysql_fetch_array($result)) 
    {
      $tree->add(array(
        'title' => $node['title'],     
        ), $node['parent_id']
      );
    
}
   
    return $tree->getNodes();$tree->getNodes() will return the nodes with lft and rgt fields.

So what options do I have?

Option 1:
•A Nested Set database (with lft and rgt fields per record).
•NestedSetStore with TreeGrid
This option is good for those who wish to implement the hierarchy logic using SQL.

Option 2:
•An Adjacency List database (records having ID and Parent ID)
•Having Tree.php calculating lft and rgt
•NestedSetStore with TreeGrid
This option is good for those who wish to make life hard for themselves.

Option 3:
•An Adjacency List database
•AdjacencyListStore with TreeGrid
This option is good for those who wish to keep things simple, and don't mind implementing the hierarchy logic in PHP (or any other server-side script).

Anything else I need to know?

Be aware that the record definition varies with respect to your NestedSetStore/AdjacencyListStore choice.

With NestedSetStore you need to have the fields starting with '_':


Code:
    var record = Ext.data.Record.create([
           {name: 'company'},
         {name: 'price', type: 'float'},
         {name: 'change', type: 'float'},
         {name: 'pct_change', type: 'float'},
         {name: 'last_change', type: 'date', dateFormat: 'n/j h:ia'},
         {name: 'desc'},
         {name: '_id', type: 'int'},
         {name: '_level', type: 'int'},
         {name: '_lft', type: 'int'},
         {name: '_rgt', type: 'int'},
         {name: '_is_leaf', type: 'bool'}
       ]);With AdjacencyListStore you don't need the _level, _lft, and _rgt fields. In fact, having them can mess up the TreeGrid Display. So:


Code:
   
var record = Ext.data.Record.create([
           {name: 'company'},
         {name: 'price', type: 'float'},
         {name: 'change', type: 'float'},
         {name: 'pct_change', type: 'float'},
         {name: 'last_change', type: 'date', dateFormat: 'n/j h:ia'},
         {name: '_id', type: 'int'},
         {name: '_parent', type: 'auto'},
         {name: '_is_leaf', type: 'bool'}
       ]);Adding a Record Dynamically

The following code is based on an earlier post in this thread:


Code:
function addItemChild() {

    // get selected record
    var r = grid.getSelectionModel().getSelected();

    // if it's a leaf that make it a non-leaf
    if (r.get("_is_leaf")) {
        r.set("_is_leaf", false);
    }

    childID = Ext.id();
    var myNewRecord = new record({company:"Child " + childID, price:12, _id:childID, _is_leaf:true, _parent:r.get("_id")}, childID);
    store.addSorted(myNewRecord);
}
A few notes on this:

1) When using EditorGridPanel, I have found the need to replace this line:


Code:
var r = grid.getSelectionModel().getSelected();
With:

Code:
row = grid.getSelectionModel().getSelectedCell()[0];
r = store.getAt(row);2) 
Notice the use of:

Code:
new record({...}, id)Where record was defined earlier:


Code:
var record = Ext.data.Record.create([...]);
This is instead of using:


Code:
new Ext.data.Record({...}, id);3) 
This example applies to AdjacencyListStore. If you want to add a record to a NestedSetStore, you'd need to provide _lft, _rgt and _level (most likely you'd have the server doing this, possible calculating these using the Tree helper class).

4) I have found the need to include the following for the tree to update correctly (mainly with regards to the icons displayed next to the node):


Code:
         
store.addSorted(myNewRecord);
          // the two lines below are added so the grid updates correctly
          store.expandNode(r);          
          grid.getView().refresh();
Using Direct with TreeGrid

I got TreeGrid working with direct by replacing the following in treegrid.js:

This:

Code:
Ext.ux.maximgb.tg.AbstractTreeStore = Ext.extend(Ext.data.Store
,Has changed to this:


Code:
Ext.ux.maximgb.tg.AbstractTreeStore = Ext.extend(Ext.data.DirectStore
,And then in my code:


Code:
  
 var store = new Ext.ux.maximgb.tg.AdjacencyListStore({
        autoLoad : true,
        directFn : nodes.get,
        reader: new Ext.data.JsonReader({id: '_id'}, record),
    });
Hope this helps
分享到:
评论

相关推荐

    ux.maximgb.treegrid

    "ux.maximgb.treegrid" 是一个针对Extjs框架的扩展插件,专门用于实现树状表格的功能。在Web开发中,尤其是数据管理界面,树形表格是一种常见且实用的数据展示方式,它将数据以层级结构展示,既方便了用户理解和操作...

    Ext.ux.tree.treegrid异步加载

    本文详细介绍了如何使用ExtJS中的`Ext.ux.tree.TreeGrid`组件实现异步加载功能,包括前端配置和后端数据处理两个方面。通过这种方式可以有效提升用户体验,同时减轻服务器的压力。在实际开发过程中,还需要根据具体...

    ux.maximgb.tg.zip

    【标题】"ux.maximgb.tg.zip" 是一个压缩包文件,可能包含了一个名为 "ux.maximgb.tg" 的开源项目或者库。通常,这样的命名格式表明它是由用户 "maximgb" 创建或维护的,并且可能与UI组件或者数据展示有关,特别是...

    jquery.treegrid.min.js

    jquery.treegrid.min.js jquery.treegrid.min.jsjquery.treegrid.min.jsjquery.treegrid.min.js

    ext treegrid

    "ext.ux.tree.treegrid" 指的是这个组件属于Ext JS的一个第三方插件(UX),UX是Ext JS社区为扩展其核心功能而创建的一系列用户界面组件。这些组件通常不是官方提供的,但它们丰富了Ext JS的功能,使得开发者可以更...

    TreeGrid.js 表格树插件

    TreeGrid.js是一款强大的基于jQuery的表格树插件,它为数据展示提供了一种灵活且具有层次结构的方式。这款插件允许用户将数据以表格的形式展现,并且每行数据可以展开成一个子节点,形成树状结构,使得复杂的数据...

    Ext 3.2的一个TreeGrid

    感谢 Ericzhen 远离颠倒梦想,蕴籍无上清凉 这里引用它的资源 仅作分享 http://www.cnblogs.com/Ericzhen/archive/2012/06/11/2545186.html

    基于layui的树表格-treeGrid

    本篇文章将深入探讨基于layui的树表格-treeGrid的实现原理、使用方法以及相关的知识点。 1. layui框架介绍: layui是一款模块化的前端框架,支持CSS、JS和HTML,提供了丰富的UI组件,如表格、表单、按钮、弹窗等,...

    jquery.treegrid.extension.js

    扩展jquery.treegrid.extension.js,实现jquery-treegrid的懒加载,结合jquery.cookie.js来实现缓存,减缓页面大量数据加载

    dataTables.treeGrid.js

    此为个人修改版本。初始版本为: https://blog.csdn.net/lhmyy521125/article/details/86528502 《DataTables TreeGrid 插件 可以快速实现树形表格》

    jquery-treegrid 树形表格组件

    <link rel="stylesheet" href="jquery.treegrid.css"> <script src="jquery.js"> <script src="jquery.treegrid.js"> <th data-field="id">ID 名称 大小 <!-- 数据行 --> $(function() { ...

    treegrid.zip_treeGrid wpf_treegrid_treegrid wpf c#_wpf 树状表格_wpf树

    我们将基于“treegrid.zip”这个压缩包中的资源,特别是名为“TreeGrid1”的文件,来解析和理解如何创建和使用WPF TreeGrid。 首先,让我们理解树形表格的基础概念。TreeGrid是一种控件,它允许用户以树形结构展示...

    bootstrap-treegrid.js

    自己封装的bootstrap-treegrid.js来实现树形菜单

    dataTables.treeGrid:DataTables.treeGrid.js修复版

    2020-4-16:千呼万唤始出来,很多朋友再CSDN博客上反馈了插件的一些问题,博主的公司因为已经很少用dataTable(都使用VUE啦)所以很少去弄这款插件了,今天呢总算抽时间完善了这款插件,更新内容如下: 1、解决...

    javascript treegrid

    JavaScript TreeGrid是一种在Web开发中常用的交互式数据展示控件,尤其适用于呈现具有层次...通过深入理解并实践提供的这些文件,开发者能够熟练掌握TreeGrid的使用,从而在项目中创建出高效且用户友好的数据展示界面。

    treegrid的使用详解

    本篇文章将深入探讨TreeGrid的使用,包括其基本概念、JSON数据格式、实现方法以及相关的配置选项。 首先,我们要理解TreeGrid的基本功能。TreeGrid将普通的表格数据扩展为具有折叠和展开特性的树状结构,每个行都...

    可编辑TreeGrid

    在给定的文件"ux.maximgb.tg"中,这可能是一个第三方扩展插件,提供了额外的功能或优化,使得可编辑的TreeGrid更加易用或高效。使用这样的插件,开发者可以更轻松地集成和定制可编辑的TreeGrid,提高开发效率。 总...

    bootstrap-table-treegrid.js

    bootstrap-table-treegrid.js

    jqgrid treegrid使用实例下载

    在提供的压缩包文件中,"TreeGrid.rar" 和 "TreeGrid_1.1.rar" 可能包含了 jqGrid TreeGrid 的示例代码和文档,这对于理解如何在实际项目中使用这个功能非常有帮助。通过学习这些示例,你可以更深入地了解 jqGrid ...

Global site tag (gtag.js) - Google Analytics