Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    TreeGrid or ListGrid with groups

    Hi,

    I'm not sure if I should choose the TreeGrid or the ListGrid to display some data, each of them has some properties that I like, but that I can't figure out how to get with the other one.

    The data I want to display is a list of items, each belonging to a category, and I want to display them as belonging to that category. Now, I could either use the ListGrid with the categories as groups, or I could use a TreeGrid with the categories as folder-nodes and the items as leaf-nodes.

    I really like the visual representation of the ListGrid with groups, but I have some problems with it. First, I want the user to be able to Drag-and-Drop items between the different groups, but also rearranging the items within a group as well as rearranging the groups, and I haven't found a way to do that with the ListGrid. (When you enable groups, it seems like item's positions are determined by the sorting algorithm). Besides that, I will need empty groups as where the user can drop items, and I would also like the user to be able to edit the group labels. It is beginning to sound as the TreeGrid is a better choice, right?

    First, I would have to limit the user so that he can't drag one category into another, but I believe that is possible by listening to drag events. Second, the items would be displayed as a multicolumn tree, but the category/group/folders nodes does only have a name and not all the other properties that the items have. Is it possible to have nodes with different columns in a TreeGrid? Or do you have any other suggestions to solve this problem?

    All suggestions are welcomed, thanks!

    #2
    node with a single column

    I think you might use setSingleCellValue to show category nodes like a group (a single column row).

    From help:
    void com.smartgwt.client.widgets.grid.ListGridRecord.setSingleCellValue(String singleCellValue)
    Default property name denoting the single value to display for all fields of this row. If this property is set for some record, the record will be displayed as a single cell spanning every column in the grid, with contents set to the value of this property.
    Note: this attribute name is governed by singleCellValueProperty.

    Parameters:
    singleCellValue singleCellValue Default value is null

    Comment


      #3
      Thank you falco!

      I tried the following code
      Code:
      TreeGrid tg = new TreeGrid();
      tg.setCanEdit(true);
      tg.setCanReorderRecords(true);
      tg.setWidth(500);
      tg.setHeight(400);
      
      TreeGridField nameField = new TreeGridField("Name");
      TreeGridField valueField = new TreeGridField("Value");
      TreeGridField commentField = new TreeGridField("Comment");
      tg.setFields(nameField, valueField, commentField);
      
      Tree t = new Tree();
      TreeNode root = new TreeNode();
      t.setRoot(root);
      
      TreeNode category = new TreeNode();
      category.setSingleCellValue("Single cell value");
      t.add(category, root);
      
      for(int i=0;i<10;++i) {
      	TreeNode item = new TreeNode();
      	item.setAttribute("Name", "Node "+i);
      	item.setAttribute("Value", ""+(i*i));
      	item.setAttribute("Comment", "Comment "+i);
      	t.add(item, category);
      }
      
      tg.setData(t);
      layout.addMember(tg);
      and it almost work as I intended, however I have two problems.
      First, the singleCellValue-node only spans two of the three columns, which I believe is a bug?
      Second, it seems like the singleCellValue-node can't be edited even when I enable editing for the rest of the nodes.

      More ideas on these issues are very welcomed, thanks!

      Comment


        #4
        Hi everyone,

        any suggestion using ListGrid implementation rather than TreeGrid?


        Thank you in advanced

        Comment


          #5
          Originally posted by aryen
          Hi everyone,

          any suggestion using ListGrid implementation rather than TreeGrid?


          Thank you in advanced
          Can you elaborate on your question?

          Comment

          Working...
          X