EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: vladj on August 23, 2018, 06:00:10 AM



Title: treegrid Jquery: folder is converted to file after all children are removed.
Post by: vladj on August 23, 2018, 06:00:10 AM
Hi!

I am writing an app presenting some tree-like structure, similar to file structure on disk. I found that after last child is removed folder icon is replaced by file. This is not how file system behaves - even if you remove all files folder stays folder. Similarly replacing the folder by file is not the desired behavior for my app.

Looking at the code of jquery.ui.min.js I see that this is done intentionally. Here is a snippet inside of DeleteRow:

   var _a15 = del(id);
   if (_a15) {
         if (_a15.children.length == 0) {
         tr = opts.finder.getTr(_a14, _a15[opts.idField]);
         tr.next("tr.treegrid-tr-tree").remove();
         var cell = tr.children("td[field=\"" + opts.treeField + "\"]").children("div.datagrid-cell");
         cell.find(".tree-icon").removeClass("tree-folder").addClass("tree-file");
         cell.find(".tree-hit").remove();
         $("<span class=\"tree-indent\"></span>").prependTo(cell);
      }
   }

So my question is: besides just commenting out this code - which I would hate to do - can you propose some more legitimate way of achieving what I want to achieve? Something with prototyping?

Thanks!


Title: Re: treegrid Jquery: folder is converted to file after all children are removed.
Post by: jarry on August 23, 2018, 05:18:47 PM
The 'tree-file' indicate if the node is a leaf node. If no child nodes exist, it acts as a leaf node. If you want to make a leaf node become a folder, please add a customer icon class to this node.
Code:
{
  "id":21,
  "name":"Java",
  "size":"",
  "date":"01/13/2010",
  "state":"closed",
  "iconCls":"myfolder",
}

And then define this 'myfolder' style.
Code:
<style type="text/css">
  .myfolder.tree-file{
    background-position: -208px 0;
  }
</style>