EasyUI Forum
March 28, 2024, 11:45:38 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: treegrid - create hierarchical json data from MySQL in php without loadFilter  (Read 24113 times)
andyj
Jr. Member
**
Posts: 57



View Profile
« on: July 28, 2013, 02:30:49 PM »

I worked out how to correctly format the json data source in hierarchical format using php.
This means you don't have to use the loadFilter method.

Example of a correctly formatted JSON output (not based on my php select query - just in terms of structure):
Code:
[{  
    "id":1,  
    "text":"Folder1",  
    "iconCls":"icon-save",  
    "children":[{  
        "text":"File1",  
        "checked":true  
    },{  
        "text":"Books",  
        "state":"open",  
        "attributes":{  
            "url":"/demo/book/abc",  
            "price":100  
        },  
        "children":[{  
            "text":"PhotoShop",  
            "checked":true  
        },{  
            "id": 8,  
            "text":"Sub Bookds",  
            "state":"closed"  
        }]  
    }]  
},{  
    "text":"Languages",  
    "state":"closed",  
    "children":[{  
        "text":"Java"  
    },{  
        "text":"C#"  
    }]  
}]

Here is the data_select.php file.
Note:
id field is account_id
parent id field is parent_id
Code:
<?php
include '../../common/conn.php';

$refs = array();
$list = array();
 
$sql "SELECT
account.account_id,
account.AccountName,
account.parent_id,
account.AccountType,
account.AccountNumber
FROM
account"
;
$result mysql_query($sql);
while(
$data = @mysql_fetch_assoc($result)) {
    
$thisref = &$refs$data['account_id'] ];
 
    
$thisref['account_id'] = $data['account_id'];
    
$thisref['AccountName'] = $data['AccountName'];
    
$thisref['parent_id'] = $data['parent_id'];
    
$thisref['AccountType'] = $data['AccountType'];
    
$thisref['AccountNumber'] = $data['AccountNumber'];
 
    if (
$data['parent_id'] == 0) {
        
$list[  ] = &$thisref;
    } else {
        
$refs$data['parent_id'] ]['children'][] = &$thisref;
    }
}

$mylist["rows"] = $list

echo 
json_encode($mylist);
?>

The above will extract ALL records.
Note: parent_id should be '0' by default not NULL.

Does anyone know how to use this method to combine it with support for pagination? Ideally I would like to expand all nodes by default but offer pagination...
« Last Edit: July 29, 2013, 01:10:51 AM by andyj » Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: July 29, 2013, 09:25:06 AM »

The tutorial below shows how to add pagination to treegrid.
http://www.jeasyui.com/tutorial/tree/treegrid4.php
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!