TreeTable SamplesTreeTable

Sample list

  1. Tree-grid
  2. Simple grid
  3. Checkbox in cell
  4. Editing of cell value - simple input field
  5. Editing of cell value - drop-down list (combobox)
  6. Dragging of columns - reordering
  7. Hyperlink in cell
  8. Popup menu
  9. Multilanguage support (japanese)
  10. Dynamical loading - ASP code sample
  11. Dynamical loading - JSP code sample
  12. Component version - Java code sample

1. A real treegrid:

2. A simple table (from NorthWind.mdb):

Below we demonstrate most attractive features of the advanced version:

3. Checkbox in any cell:

4. Editing of cell value - simple input field:

5. Editing of cell value - drop-down list (combobox):

6. Dragging of columns - reordering:

7. Hyperlink in cell:

8. Popup menu:

9. Multilanguage support (japanese):

10. Dynamical loading - ASP code sample: zip (8 kB)

<%
Delim = "@"
ParentId = request("id")
ParentId = mid(ParentId,2)
Set con = getConnection()

Set rs = con.Execute("select * from Bookstore_Categories" &_
  " where ParentId=" & ParentId & " order by Id")
Do While Not rs.EoF
  id = "c" & rs("id")
  text = rs("name")
  response.write  id & Delim & text & Delim & id & Delim &_
   "1" & Delim & "#ffffff" & Delim & "2" & Delim & "2"
  response.write vbCrLf
  rs.MoveNext
Loop
rs.close()
Set rs=Nothing

Set rs = con.Execute("select * from Bookstore_Books" &_
  " where CategoryId=" & ParentId & " order by Id")
Do While Not rs.EoF
  id = "b" & rs("id")
  title = rs("Title")
  author = rs("Author")
  dscr=rs("Description")
  icon=rs("Icon")
  url=rs("URL")
  if title="" then title=" "
  if author="" then author=" "
  if dscr="" then dscr=" "
  if icon="" then icon=" "
  dscr = replace(dscr,vbLf,"\n")
  url = replace(url,vbLf,"\n")
  text =  title & "|" & author & "|" & dscr & "|" & icon & "|" & url
  response.write  id & Delim & text & Delim & id & Delim &_
   "0" & Delim & "#ffffff" & Delim & "3" & Delim & "3"
  response.write vbCrLf
  rs.MoveNext
Loop
rs.close()
Set rs=Nothing

con.close()
Set con=Nothing
%>

11. Dynamical loading - JSP code sample: zip (3 kB)

<%
String id=request.getParameter("id");
int k=id.indexOf(",");
int lev=Integer.parseInt(id.substring(0,k));
int newLev=lev+1;
id=id.substring(k+1);

Connection con = getConnection();
Statement st = con.createStatement();

if(lev==0)
{

ResultSet rs = st.executeQuery("select * from customers");
while(rs.next())
{
  String rs_id=newLev + ",'" +rs.getString("CustomerID")+"'";
  String rs_lbl=rs.getString("CompanyName");
  out.println(rs_id + "@" + rs_lbl + "@" + rs_id + "@1");
}
rs.close();
}

if(lev==1)
{

ResultSet rs = st.executeQuery("select * from orders where CustomerID="+id);
while(rs.next())
{
  String rs_id=rs.getString("OrderID");
  String rs_lbl="Order #"+rs_id;
  rs_id=newLev + "," +rs_id;
  out.println(rs_id + "@" + rs_lbl + "@" + rs_id + "@1");
}
rs.close();
}

if(lev==2)
{
ResultSet rs = st.executeQuery("select t1.*,t2.productname"+
  " from [order details] t1,products t2"+
  " where t1.orderid="+id+" and t2.productid=t1.productid");

NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.US);
NumberFormat nf2 = NumberFormat.getPercentInstance(Locale.US);

while(rs.next())
{
  String rs_id=newLev + "," +rs.getString("orderid");
  String rs_lbl=rs.getString("productname");
  float rs_up=rs.getFloat("unitprice");
  int rs_q=rs.getInt("quantity");
  float rs_dc=rs.getFloat("discount");
  float ep = rs_up * rs_q * (1-rs_dc);
  rs_lbl += "|"+nf.format(rs_up)+"|"+rs_q+"|"+nf2.format(rs_dc)+"|"+nf.format(ep);
  out.println(rs_id + "@" + rs_lbl + "@" + rs_id + "@0");
}
rs.close();
}


st.close();
con.close();
%>

12. Component version - Java code sample: zip (4 kB)

import java.awt.*;
import com.scand.treetable.*;

public class Editor implements JGridListener
{
  static JTreeGrid grid=null;
  
  public static void main(String args[]) {
    Frame f = new Frame("Editor");
    
    grid = new JTreeGrid(new String[] {"Name","DoB","Salary"});
    
    grid.addGridListener(new Editor());
  
    // set this to true so user can edit cells and checkboxes
    // you can disable editing of particular cell
    // using cellEdited event handler, see below
    //grid.is_editable = true;    
    grid.setHorAligns(new String[] {"l","c","r"});
  
    // 0 - no lines, 1 - dotted. 2 - solid.
    grid.treelines = 2;
  
    // set true to draw grid borders
    grid.draw_grid = true;  // false default

  
    // set true so user can drag(reorder) columns
    grid.is_coldraggable = true;  // false default
  
    // set true to enable tree level checkboxes
    grid.chk_enable = true;  //false default
    
    grid.addIcon("icons/item_closed.gif","0");
    grid.addIcon("icons/item_opened.gif","1");
    grid.addIcon("icons/item_node.gif","2");
    
    grid.insertRoot("1", "Dev Team", "1", "0","1");
    grid.insertNewChild("1", "2", 
      "Petrov Petr$07/04/1972$<checkbox state='1'>200", "2", "2","2");
    grid.insertNewChild("1", "3",
      "Sidoro Gine$01/05/1971$<img='icons/item_root.gif'/>", "3", "2","2");
    grid.insertRoot("4", "QA Team", "4", "0","1");
    grid.insertNewChild("4", "5", "Drtyyu Outr$05/03/1975$500", "5", "2","2");
    grid.insertNewChild("4", "6", "Vaacre Uvee$03/07/1972$100", "6", "2","2");
    
    grid.cells("header_row",0).setBgColor("#ff0000");
    grid.cells("header_row",0).setTextColor("#ffffff");
  
    grid.cells("2",2).setBgColor("#ffcccc");
    grid.cells("2",0).underline = true;
    grid.cells("2",1).setFont("Dialog-bold-16");
    grid.openItem("1");
    grid.closeItem("4");
    grid.setSelectedRow("2",false,true);
    
    
    grid.initMenu(new String[] {"A","B","C"});
  
    f.add("Center", grid);
    f.resize(400, 300);
    f.show();
  }
  
  // you can rename this method to main() to test GRID mode, not TREEGRID

  public static void main2(String args[]) {
    Frame f = new Frame("Editor");
    
    JGrid grid = new JGrid(new String[] {"Name","DoB","Salary"});
    grid.setHorAligns(new String[] {"l","c","r"});
    
    grid.addRow("1", new String[] {"Ivanov Ivan","01/01/1973","$300"}, "1");
    grid.addRow("2", new String[] {"Petrov Petr","01/03/1971","$200"}, "2");
    grid.addRow("3", new String[] {"Antone Anto","06/05/1975","$100"}, "3");
    grid.addRow("4", new String[] {"Serute Serg","04/07/1972","$500"}, "4");
    grid.addRow("5", new String[] {"Victor Vict","01/06/1975","$800"}, "5");
    
    grid.cells("2",2).setBgColor("#ffcccc");
    grid.setSelectedRow("2",false,true);
    
    f.add("Center", grid);
    f.resize(300, 300);
    f.show();
  }

  public Boolean keyPressed(java.awt.event.KeyEvent e) {
    System.out.println("keyPressed: " + e.getKeyCode());
    return new Boolean(true);
  }

  public Boolean cellEdited(int type, String rowID,int column) {
    System.out.println("cellEdited: type=" + type);

    if(type==0) {  
      // Beginning of editing
      // You may return false here to disable editing of this cell
      if(rowID.equals("2") && column==1) return new Boolean(false);
    } else if(type==1) {  
      // This event type happens on each new character entered into the cell
      // This event type also happens when a checkbox in the cell is clicked
      // But not for the tree level chekcboxes - for this checkboxes another
      //  event handler exists: treeCheckbox() see below.
    } else if(type==2) {  
      // This happens when editig is finished and you leave the cell

    } else if(type==21) {  
      // This happens when ENTER key is pressed
    }
    return new Boolean(true);
  }

  public void rowClicked(String action, int column) {
    System.out.println("rowClicked: " + action);
  }

  public void rowDoubleClicked(String rowID, int column) {
  }

  public void rowLinkClicked(String link) {
  }

  public void rowSelected(String rowID, boolean multi) {
  }

  public void menuClicked(String action, String rowID, int column) {
    System.out.println("menuClicked: "+action);
  }

  public void menuInit(String rowID, int column) {
  }

  public void nodeOpened(String rowID) {
  }

  public void nodeClosed(String rowID) {
  }

  public void treeCheckbox(String rowID, int checkState) {
    System.out.println("treeCheckbox: " + rowID
      + " checkState: " + checkState);
    if(rowID.equals("6")) {
      grid.insertNewChild("6", "55",
        "New item$03/07/1972$100", "55", "2","2");
      grid.openItem("6");
  }
 }
}

Questions or comments? Write us, you are always welcome.
Check our other products.