Author Topic: Tree grid shows leaf icon even if there is no child records  (Read 413 times)

gopigupta

  • Pro Ultimate
  • Newbie
  • *
  • Posts: 37
    • View Profile
Tree grid shows leaf icon even if there is no child records
« on: January 05, 2024, 01:12:50 pm »
Hello,

I am using tree grid(vs.9.0.2). When child node is added, parent row shows leaf icon to indicate it has child rows(ScreenShot1). when I rollback changes using below code, the parent row still show leaf icon even though it does not contain any child rows(ScreenShot2).

GridApi.rollback();
GridApi.refreshDataAndView();

Can you please provide solution on how to remove leaf icon if parent node does not have any child nodes 

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6282
    • View Profile
Re: Tree grid shows leaf icon even if there is no child records
« Reply #1 on: January 05, 2024, 01:44:04 pm »
Please use leafIfEmpty property of treeModel.

https://paramquery.com/pro/api#option-treeModel

gopigupta

  • Pro Ultimate
  • Newbie
  • *
  • Posts: 37
    • View Profile
Re: Tree grid shows leaf icon even if there is no child records
« Reply #2 on: January 05, 2024, 05:04:59 pm »
Thank you for quick reply.

The solution provided below(leafIfEmpty property) only works well if we use deleteNodes to remove child nodes. I want to undo all changes so I have used rollback followed by refreshDataAndView. Adding leafIfEmpty: true does not solve issue in this case.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6282
    • View Profile
Re: Tree grid shows leaf icon even if there is no child records
« Reply #3 on: January 05, 2024, 10:41:30 pm »
Please use this fix ( change event callback )

Code: [Select]
//fix leafIfEmpty for rollback.
change: function(evt, ui){

var T = this.Tree();
if(ui.source == 'rollback' && ui.deleteList.length ){
T.refreshViewFull();
ui.deleteList.forEach(function( obj ){
var parent = T.getParent( obj.rowData );
if( parent && T.isEmpty(parent) )
T.makeLeaf( parent );
})               
}
},

gopigupta

  • Pro Ultimate
  • Newbie
  • *
  • Posts: 37
    • View Profile
Re: Tree grid shows leaf icon even if there is no child records
« Reply #4 on: January 08, 2024, 10:12:43 am »
Thank you for providing solution.