Kamran Ali
Kamran Ali

Reputation: 5954

how to change icon for parent node when all of its children are deleted in jqGrid Tree Grid

I'm using jqGrid Tree grid for displaying some hierarchical data. I've to implement the delete functionality and so far so good its done, only thing that is causing a problem "is that when all the children of a specific node is are deleted then this node should become a leaf node i.e. its icon should be changed from arrow to leaf one"

I'm using following code to delete the node from the grid

$trackerGrid.jqGrid('delTreeNode', actoinItemEntityId);
var record = getRowRecord(baseId);
var siblingArray = $trackerGrid.jqGrid('getNodeChildren', record);

if(!siblingArray || !siblingArray.length) {                                         

    $trackerGrid.jqGrid('collapseNode', record);
    setLeafColumnValue(baseId, false);  
}

the nodes gets deleted successfully but the icon of parent does not change and the icon remains that of expanded node. Anybody got any idea about this?

Upvotes: 0

Views: 859

Answers (1)

Oleg
Oleg

Reputation: 221997

In common case a Node without children in the TreeGrid is not the same a Leaf. You can imagine node as folder and leaf as file. Even if you delete all files from the folder it will be stay folder and will be not converted to file.

If in your use case the behavior which you describe have sense I would recommend you to do following:

  • to get the current data from the empty node. I think you can use getLocalRow to get local data by rowid;
  • delete the node which has now no children;
  • and then add new node using addChildNode with the same data as before, but with isLeaf: true.

In the case you will have code which hold all standards of TreeGrid and it will work in next versions of jqGrid.

Upvotes: 1

Related Questions