Forum
05:28
26/05/2009
Hi,
I could not get the treegrid demo to work. Looking at the code (server.php?q=tree2) I found this SQL statement
SELECT account_id, name, acc_num, debit, credit, balance, level, lft, rgt FROM accounts WHERE 0=0 ORDER BY lft
I seem to be missing level, lft and rgt fields and values for this table.
I have search the forums for ltf and rgt and came up with zip
Does anyone have the sample data for treegrid?
regards
AA
12:01
Moderators
30/10/2007
Hello,
Thanks will update the demo soon.
Best Regards
Tony
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
10:33
22/12/2008
here's mine,enjoy.
test.js:
var gridimgpath = '../css/theme/redmond/images';
$(document).ready(function(){
treeview();
});
function treeview() {
$('#treeGrid').jqGrid({
treeGrid: true,
treedatatype: 'json',
rowNum: -1,
url: 'manage_column_aj.php?aj=10',
datatype: 'json',
treeModel : 'nested',
mtype: 'POST',
colNames:['id', name', 'name2', 'type', 'display in webheader', 'image', 'column level', 'imagelink'],
colModel:[
{name: 'id', index:'nodeid', width:50, fixed:true, hidden:false, editable:false, key:true, align:'center', formoptions:{rowpos:1} },
{name: 'name', index:'name', width:500, align:'left', editable:true,
editrules:{required: true}, formoptions:{elmsuffix:' *'}, editoptions:{maxlength: 15} },
{name: 'ename', index:'ename', width:100, align:'center', editable:true, editoptions:{maxlength: 15} },
{name: 'colType', index:'colType', width:50, align:'center',
editable:true, edittype:'select', editoptions:{value: {1:'listNews', 2:'articleNews', 4:'imageNews'}}, formatter:'select' },
{name: 'showInHead', index:'showInHead', width:60, fixed:true, align:'center',
editable:true, edittype:'checkbox', formatter:'checkbox', editoptions:{value: '1:0'} },
{name: 'image', width:100 , sortable:false, editable:false , hidden:true, formatter:'link' },
{name: 'lvl', index:'n_lvl', width:50, fixed:true, sortable:false, align:'center', editable:false },
{name: 'imageLink', index:'imageLink', width:100, align:'center', editable:false, edittype:'file', editrules:{edithidden: true} }
],
ExpandColumn : 'name',
ExpandColClick: true,
autowidth: true,
viewrecords: true,
height: 'auto',
pager : $('#ptreeGrid'),
imgpath: gridimgpath,
caption: 'Manage Column',
editurl: 'manage_column_aj.php'
})
.jqGrid('navGrid', '#ptreeGrid',
{view: true, edit: true, add: true, del: true, search: false, refresh: true},
// edit options
{top:150, left:250, reloadAfterSubmit: false, jqModal: false, closeOnEscape: true, bottominfo: '', closeAfterEdit: true},
// add options
{top:150, left:250, reloadAfterSubmit: true, jqModal: false, closeOnEscape: true, bottominfo: '*', closeAfterAdd: true,
onclickSubmit : function() {
var rowid = $(”#treeGrid”).getGridParam('selrow');
adddata = {id : rowid};
return adddata;
},
afterSubmit : function(r, postdata) {
var rd = eval('(' + r.responseText + ')' );
r = null;
var state = (rd.state > 5 && true);
return [state, rd.msg, 0];
}
},
// del options ?strange reloadAfterSubmit:ture will COPY root, then TWO root will be shown!
{top:150, left:250, reloadAfterSubmit: false, jqModal: false, closeOnEscape: true,
afterSubmit : function(r, postdata) {
var rd = eval('(' + r.responseText + ')' );
r = null;
var state = (rd.state > 5 && true);
return [state, rd.msg, 0];
}
},
{closeOnEscape: true}, // search options
{jqModal: false, closeOnEscape: true} // view options
);
}
11:00
22/12/2008
i use PEAR:MDB2 for db connect
manage_column_aj.php:
function make_treecolum($db) {
$nodeId = !isset($_POST['nodeid']) || intval($_POST['nodeid'])<1 ? 1 : intval($_POST['nodeid']);
$deep = 3; // can not less 2, or Duplicat root will be shown
$res = get_column($nodeId, $deep, $db);
if (!$res) {return false;}$count = count($res);
$out = array('page'=>1, 'total'=>1, 'records'=>$count);
foreach ($res as $row) {
$colType = $row['sort_type'];
if($row[rgt] == $row[lft]+1) {
$leaf = true;
}
else {
$leaf = false;
$colType = 0;
}$id = $row['id'];
$name = $row['sort_name'];
$ename = $row['sort_ename'];
$image = $row['sort_pic'];$lvl = $row['level'];
$lft = $row['lft'];
$rgt = $row['rgt'];
$shoInHeader = $row['isdispaly'];
$expand = $lvl<$deep-1 ? TRUE : FALSE;
$out['rows'][] = array('id'=>"$id",
'cell'=>array($id, $name, $ename, $colType, $shoInHeader, $image, $lvl,
$image, $lvl, $lft, $rgt, $leaf, $expand)
);
}echo json_encode($out);
}/**
* get Nested
*
* @param int $nodeId
* @param int $deep
* @return array
*/
function get_column($nodeId = 1, $deep = 3, $db) {
$nodeId = $nodeId < 1 ? 1 : $nodeId;
// detect if here we post the data from allready loaded tree
// we can make here other checksif( $nodeId >1) {
$node = get_columnInfo($nodeId);
$n_lft = $node['lft'];
$n_rgt = $node['rgt'];
$n_lvl = $node['level'] + 1;$sql = 'SELECT * FROM tb_sort2 WHERE lft>' .$n_lft . ' AND lft<' .$n_rgt .' AND level=' .$n_lvl .' ORDER BY lft';
}
else {
// initial grid
$sql = 'SELECT * FROM tb_sort2 WHERE level<' .$deep .' ORDER BY lft';
}
$res = $db->queryAll($sql);
$e = isMDB2Error($res);
if ($e != false) {
die('err');
}
else {
return $res;
}}
11:01
22/12/2008
database:
CREATE TABLE `tb_sort2` (
`id` int(11) unsigned NOT NULL auto_increment,
`lft` int(11) unsigned NOT NULL default '0' COMMENT 'Nested left_field',
`rgt` int(11) unsigned NOT NULL default '0' COMMENT 'Nested right_field',
`level` smallint(6) unsigned NOT NULL default '1' COMMENT 'Nested tree level',
`sort_name` varchar(255) default '',
`ctype` tinyint(1) unsigned default '0' COMMENT 'is PhotoNews Column',
`sort_type` tinyint(1) unsigned default '1' COMMENT 'display type:1-show newslists, 2-show news, 4-photo news',
`sort_url` varchar(100) default '',
`sort_ename` varchar(50) default '',
`isdispaly` tinyint(1) unsigned default '0' COMMENT '1-display in header menu',
`order_id` tinyint(4) unsigned NOT NULL default '255' COMMENT 'ASC max255 min1',
`sort_pic` varchar(255) default '',
`is_en` tinyint(1) unsigned default '0',
PRIMARY KEY (`id`),
KEY `rgt` (`rgt`),
KEY `lvl` (`level`),
KEY `lft_lvl` (`lft`,`level`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;
Most Users Ever Online: 715
Currently Online:
37 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66