|
steven
|
 |
« on: February 01, 2009, 09:39:31 PM » |
|
With experience of Tutorial 4, you have known how to display data from real database in a grid. In this section, we will continue to learn how to load data from database into a tree. [Req Spec]1. A tree is needed. 2. When end user click on a node, its children nodes will be retrieved and displayed. [Do It Yourself]We need prepare a data table first. If you don't know how to store a tree in one data table, I can tell you. We assume every record in table is for one node. You need two columns for each record to describe their relationship. One is id, another is its parent id. Since root node has no parent, we assume its parent to be a negative value. Simply create a database named testdb and execute the following sql. 1. Firstly, prepare a file named treenode.php to http://localhost/treenode.php. This php script take a parent id as a parameter and return their children nodes. It reads 2. Drag a [treeBar] to design area,set its alias to "treebar1"(Click dialog window to select it, type "treebar1" in [Component Config Window]->[alias],and strike [Enter] on keyboard. ) 3. Change its initial nodes. (Click [treebar1] to select it,click on right side of [Component Config Window]->[properties]->[items],a small button will appear. Click this button, a dialog box will pop up.) The popup is saying Change it to the following line. Make sure set "sub" to true. That means is a parent node, but its children info is not known. When end user expand this node, onGetContent will be fired. 4. Add event handler for parent node being expanded. (Click [treebar1] to select it,click on right side of [Component Config Window]->[events]->[onGetContent],a small button will appear. Click this button, a dialog box will pop up.) 5. You will see the following lines in the dialog 6. In the handler, we will call linb.request. 7. A very important thing I have to say is rep above is string in type. So we need to convert it to nodes array. Function _.unserialize is introducted here (also see http://www.sigmawidgets.com/products/sigma_visual/API/index.html#_.unserialize). _.unserialize (str, dateformat) This function can help you convert string to Javascript object. It takes two parameters. We could ignore the second parameter because we have no date variables to deal with. Think of the following code. The lines will popup an alter box saying 25. 8. After you understand unserialize, We could complete code look like 9. Click [OK] to close dialog. 10. Press [run] to see the result.
|
|
|
|
|
Logged
|
Sigma AJAX Data Grid - Easy to Integrate with PHP, ASP Classic, ASP.NET & Java Sigma PHP Ajax Framework - WYSIWYG GUI Builder With Tree, Grid, Treegrid, Dialog, Tab & More Component
|
|
|