Dynamic grouping

Posted by: Ranba790 on 25 July 2018, 7:47 am EST

    • Post Options:
    • Link

    Posted 25 July 2018, 7:47 am EST

    Hi

    I added dynamic grouping to a flexgrid bound to a datatable which get updated every few seconds.

    The feature works and i can see the grouping, When using the (+) sign to collapse the group, it will collapse but after the data table is updated (every couple of seconds) with new data it will expend again . any way to prevent it and keeping the group collapsed

    Thanks

  • Posted 26 July 2018, 5:52 am EST

    To make the nodes of C1FlexGrid collapsed, you can make use of C1FlexGrid.Nodes[index].Collapsed property. Or, if you want to save the current state of the node rows and want them look similar after updation of datatable, you can save the value of the Collapsed property for every node in the collection and assign these values after the table has updated.

    
    foreach (var node in _grid.Nodes)
                {
                    _nodeStatus.Add(node.Collapsed);
                }
                adapter.Fill(data, startingIndex, count, _tableName);
                startingIndex = startingIndex + count;
             
                for(int i = 0; i < _nodeStatus.Count; i++)
                {
                    _grid.Nodes[i].Collapsed = (bool)_nodeStatus[i];
                }
    
    

    Please refer the attached application implementing your requirements. Do click on the “Load Data” button to load more data in the table.

    Thanks.

    DynamicGrouping.zip

  • Posted 6 August 2018, 3:32 pm EST

    I did as you recommended, the issue is that every 2 seconds when the data updated you can see the screen flickers from the scroll bar added and disappears since the data refresh expends all the nodes and I collapse them right after.

    Also,

    Is there a way to detect when a mouse is clicking the node plus sign to collapse the group or expend so I can tell the difference between user and the automatic data refresh

    Thanks

  • Posted 7 August 2018, 1:20 am EST

    Hi Ran!

    1. If you use BeginUpdate and EndUpdate methods of the grid in the above suggested code then you can get rid of this appearance issue.
    _grid.BeginUpdate();
    if (_nodeStatus!=null)
    {
            _nodeStatus.Clear();
    }
    _nodeStatus = new ArrayList();
    foreach (var node in _grid.Nodes)
    {
            _nodeStatus.Add(node.Collapsed);
    }
    adapter.Fill(data, startingIndex, count, _tableName);
    startingIndex = startingIndex + count;
             
    for(int i = 0; i < _nodeStatus.Count; i++)
    {
             _grid.Nodes[i].Collapsed = (bool)_nodeStatus[i];
    }
    _grid.EndUpdate();
    

    In addition, here are some performance-improving tips:

    http://help.grapecity.com/componentone/NetHelp/c1flexgrid/webframe.html#flexgridforwinformsttoptips.html

    1. Use BeforeMouseDown event to see whenever expand/collapse icon is clicked by the user.
    private void _grid_BeforeMouseDown(object sender, BeforeMouseDownEventArgs e)
    {
           HitTestInfo hti = _grid.HitTest(new Point(e.X, e.Y));
           if(hti.Type == HitTestTypeEnum.OutlineTree)
           {
                    //Expand/Collapse Icon clicked.
           }
    }
    

    In this code, as you see, HitTestInfo will help you in getting index of group row clicked.

    Best regards,

    Meenakshi

  • Posted 1 October 2019, 10:28 am EST

    Hi

    Would you be able to provide a sample please ?

    It looks like this code doesn’t work if the user edits one cell of the grid, which seems to fully refresh the grid (and lose the collapsed state of some categories)

    Thanks

  • Posted 3 October 2019, 6:53 am EST

    Hi,

    You’re right. When a cell is edited grouping might be affected which is why the grid is refreshed. In this case, the state of the collapsed nodes is not restored. The above suggested code only restores the state when loading the data using the button.

    You can use the same approach and use the AfterDataRefresh event to restore the node states.

    You can refer to the attached sample which demonstrates this.

    DynamicGrouping_Modified.zip

    Regards,

    Jitender

  • Posted 3 October 2019, 8:29 am EST

    Thanks for your help. It does work but only in bound mode. What event should be used in unbound mode ?

  • Posted 3 October 2019, 8:36 am EST

    How are you adding data in unbound mode?

    The grid has no way to know when a batch of update completes in unbound mode, so I don’t think we can use an event in this case.

    You can just invoke the RestoreNodeStatus method after you’re done adding data to the grid.

    If you can make a small sample showing how you’re using this in unbound mode, I might be able to suggest a better method for this.

  • Posted 3 October 2019, 8:45 am EST

    My issue is not when adding data. I agree with you, when adding data, I can just restore the node status.

    My issue is when editing a row inside the grid.

    Please see the example enclosed (very close to the anayzeNew ComponentOne example).

    The usecase is :

    1- Collapse a few groups

    2- Edit the Order date on a visible Cell

    3- It looks like the grid is refreshed and all the groups are expanded

    Thanks

    file-c5ba4abb-cbe7-48e9-a67f-7a8b4335c0cc.zip

  • Posted 4 October 2019, 1:21 am EST

    Hi,

    You can do this in unbound mode:

    Keep a global boolean variable that keeps track whether the node status needs to be restored (let’s say it is _restoreNodes).

    When a cell is changed, CellChanged event will be fired. In its handler, you can set _restoreNodes to true:

    private void _grid_CellChanged(object sender, RowColEventArgs e)
    {
        _restoreNodes = true;
    }
    

    Then you can handle GridChanged event as:

    private void _grid_GridChanged(object sender, GridChangedEventArgs e)
    {
        if (_restoreNodes && e.GridChangedType == GridChangedTypeEnum.RepaintGrid)
        {
            _restoreNodes = false;
            RestoreNodeStatus();
        }
    }
    
    

    See attached sample for the example.

    DynamicGrouping_Unbound.zip

    Regards,

    Jitender

  • Posted 4 October 2019, 5:35 am EST

    That helps, thank you.

    Is there any plan to put this as a basic feature of the grid ?

    It’s really not user-friendly to expand the whole grid on every update, I don’t think anyone would want this, and I think this can be considered as a bug. That’s a lot of code on my side to handle a very basic case.

    Because the grouping on the grid doesn’t interact perfectly with other features, I’ve had to manually implement the following :

    AfterFilter so grouping gets reloaded after filtering

    CellChanged + GridChanged to correctly restore the collapsing of the groups

    MouseClick + KeyPress to save the collapsing of the groups

    Thanks

  • Posted 4 October 2019, 7:32 am EST

    Hi,

    Currently there is no plan to include this. However, we’ve asked the developers to consider this as an enhancement [Internal Tracking ID: 400691].

    We’ll let you know once we get an update from them.

    Regards.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels