Tree view in flex grid

Posted by: navyak on 29 January 2020, 2:49 am EST

    • Post Options:
    • Link

    Posted 29 January 2020, 2:49 am EST

    Hello Team,

    I am using Jquery with wijmo flex grid.

    For my requirement i need to display tree view in flex grid.

    up to one level I am displaying tree view by using ‘childItemsPath’ option.

    but not able to display tree view for grand child elements.

    Here i am attaching my sample code with data until grandchild, please let me know how to render grandchild element.

    https://drive.google.com/open?id=1ue8BVg0KSathYSTOnMgEC6IvdKVzys78

    I am attaching the screenshot on how the tree should look in grid once it is rendered.

    Let me know if you require any more information.

  • Posted 29 January 2020, 4:38 am EST - Updated 3 October 2022, 5:02 pm EST

  • Posted 29 January 2020, 11:45 pm EST

    Hi Navya,

    Simply change the childItemsPath property to just previewList:

    childItemsPath: 'previewList'
    

    If all your child data is stored in a single key, then you only need to provide the key name. We only provide an array only if the keys differ on different levels. For example, if the top-level parent has children stored in the previewList key and these children have their children stored in any other key like TemplateName.

    Also, in the image provided, Information8 also has a child, but in your data source, Information8 did not have any children.

    Let me know in case you have any further queries.

    Regards,

    Ashwin

    SampleCoreApp.zip

  • Posted 30 January 2020, 7:58 am EST

    Thank you for the reply Ashwin!.

    Now i am able to see treeview properly in flex grid.

    But as per my UI requirement, is there anyway to group the child elements (group with destinationDesc(Yes/No) and show destinationDesc name with node level indication).

    As attached in the previous image, ‘Yes’ and ‘No’ should be populated in the tree as well.

    Please let me know if you require more information.

  • Posted 31 January 2020, 1:08 am EST

    Hello Navya,

    The FlexGrid childItemsPath property allows binding with the homogeneous and heterogeneous hierarchical data.

    Please refer to the following demo sample for your reference which would guide you to show the data as per your UI requirement.

    https://www.grapecity.com/wijmo/demos/Grid/TreeGrid/ChildItems/purejs

    Hope it helps!

    Regards,

    Manish Gupta

  • Posted 3 February 2020, 3:18 am EST - Updated 3 October 2022, 5:02 pm EST

    Hello Manish,

    Thank you for your reply.

    I was going through the URL which you have mentioned, and it was helpful. But,

    as per my requirement, I need to change the collapse/expand icon too, i was able to do that using wijmo version ‘5.20193.637’.

    But in my project we are using wijmo version - ‘Wijmo Library 5.20153.109’.

    So,In tree structure I am unable to collapse/expand the items once the data is rendered.

    Following code is working fine in latest version but not working as expected in this wijmo verison 5.20153.109.

    Can you let me know what can be done so that the tree structure will be working with the icon i want in wijmo verison 5.20153.109.

    SampleApp.coreGrid.formatItem.addHandler(function (sender, e) {
                    if (e.panel.cellType !== wijmo.grid.CellType.ColumnHeader && sender.columns[e.col].binding == "TemplateID") {
                        if (sender.rows[e.row] instanceof wijmo.grid.GroupRow) {
                            // change group expand/collapse icon ; wj-elem-collapse class is required for expanding and collapsing grouped items
                            let span = '<span class="wj-elem-collapse wj-glyph-down-right"></span>';
                            if (e.panel.rows[e.row].hasChildren) {
                                if (e.panel.rows[e.row].isCollapsed) {
                                    span = ' <span class="wj-elem-collapse glyphicon glyphicon-chevron-right" >' + sender.rows[e.row].dataItem.TemplateID+'  '+ sender.rows[e.row].dataItem.TemplateName + ' </span>';
                                }
                                else {
                                    span = '<span class="wj-elem-collapse glyphicon glyphicon-chevron-down">' + sender.rows[e.row].dataItem.TemplateID + '  ' + sender.rows[e.row].dataItem.TemplateName + '</span>'
                                }
                                e.cell.innerHTML = span;
                            } else {
                                e.cell.innerHTML =  sender.rows[e.row].dataItem.TemplateID + '  '+ sender.rows[e.row].dataItem.TemplateName;
                            }
                        }
                    }
    
                });
    

  • Posted 4 February 2020, 12:58 am EST

    Hi Navya,

    The code provided is not working in the earlier version because in the earlier version, the wj-elem-collapse CSS class was not present due to which the rows are not collapsed or expanded on clicking the glyphicons. So, you will need to manually add an event listener on the FlexGrid and expand/collapse rows manually. Please refer to the code snippet below and the sample attached:

    SampleApp.coreGrid.hostElement.addEventListener('mousedown', function (e) {
    	var element = e.target;
    	if (wijmo.closest(element, '.wj-elem-collapse')) {
                    var hti = SampleApp.coreGrid.hitTest(e);
                   	let row = SampleApp.coreGrid.rows[hti.row];
            	row.isCollapsed = !row.isCollapsed;
    	}
    }, true);
    

    ~regards

    SampleCoreApp.zip

  • Posted 5 February 2020, 9:55 am EST - Updated 3 October 2022, 5:02 pm EST

    Thank you for your reply Ashwin!.

    But I am facing an issue with all the row items getting expanded autmomatically when i refresh the grid.

    In my case i have performed some operations on row items which is in groupItems(like swapped the row items info7 & info8 by using ‘Move up/down’ option) and refreshed the grid.

    Now all the group items are expanding automatically. I would like to have the group items to be in same position that it was present previously after grid getting refreshed.

  • Posted 6 February 2020, 4:52 am EST

    Hi Navya,

    If you are swapping the rows, then you must be refreshing the CollectionView of the grid. When the CollectionView is refreshed, the rows are created again, which are independent of the rows that were created before. That is why the FlexGrid does not retain the collapsed state.

    To resolve this, simply save the collapsed state of the rows in the loadingRows event and set it back again in the loadedRows event. Please refer to the code snippet below and the updated sample:

    
    var rowsMap = new Map();
    loadingRows: function (s, e) {
                        rowsMap.clear();
                        s.rows.forEach(row => {
                            rowsMap.set(row.index, row.isCollapsed);
                        });
                    },
                    loadedRows: function (s, e) {
                        setTimeout(() => {
                            s.rows.forEach(row => {
                                row.isCollapsed = Boolean(rowsMap.get(row.index));
                            });
                        });
                    }
    

    ~regards

    SampleCoreApp.zip

  • Posted 10 March 2020, 4:30 am EST - Updated 3 October 2022, 5:02 pm EST

    Hello Ashwin,

    Thank you for the reply.

    The sample code is working as expected which is given by you in chrome but i am getting syntax error

    with this ‘=>’ in IE browser and edge as well.

    Please check the below screen shot once for your reference.

  • Posted 11 March 2020, 12:02 am EST

    Hi Navya,

    The issue occurs because the arrow (=>) functions are not supported in IE. You can change the arrow functions to simple function syntax:

    loadingRows: function (s, e) {
    	rowsMap.clear();
    	s.rows.forEach(function(row) {
    		rowsMap.set(row.index, row.isCollapsed);
    	});
    }
    
    loadedRows: function (s, e) {
    	setTimeout(function() {
    		s.rows.forEach(function(row) {
    			row.isCollapsed = Boolean(rowsMap.get(row.index));
    		});
    	});
    }
    

    ~regards

  • Posted 12 March 2020, 8:00 am EST

    Thank you Ashwin.

    Now it is working as expected.

Need extra support?

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

Learn More

Forum Channels