Note that there are some explanatory texts on larger screens.

plurals
  1. POAdd new rows to jqGrid Treegrid model
    primarykey
    data
    text
    <p>We've created a jqGrid TreeGrid that represents a filesystem, where branches are folders and leafs are files. We've implemented functionality within the TreeGrid to create new "files" by using <code>addChildNode</code> which works well enough. However, we also want to add functionality to create new folders. Our script works which creates new folders, but they are not immediately displayed on the TreeGrid unless it or the page is reloaded. However, reloading the TreeGrid will collapse all the folders, which is particularly annoying.</p> <p>Is there a way to selectively refresh the nodes of the TreeGrid, or to add a new branch in that is functional? I've seen some partial documentation on <code>addJSONData</code>, but using this function completely purges the TreeGrid until refresh. I've also attempted to use <code>addChildNode</code> and change certain properties, and I've tried to add in the row manually using DOM manipulation; however, both of these methods break the node that was inserted.</p> <p>Edit:</p> <pre><code>var grid = $("#grid"); grid.jqGrid({ treeGrid: true, treeGridModel: "adjacency", ExpandColumn: 'name', ExpandColClick: true, url:"", datatype:"json", colNames:['id','Name','Authorization','Views','Uri'], colModel:[ {name:'id', index:'id', hidden:true, key:true}, {name:'name', index:'name', sorttype:"text", width:3, sortable:false}, {name:'auth',index:'auth', sorttype:"text", sortable:false, hidden:true}, {name:'views',index:'views', sorttype:"integer", width:1, sortable:false, align:"center"}, {name:'uri',index:'uri',sorttype:'text',sortable:false,hidden:true}], jsonReader:{ root:"rows" ,page:"page" ,total:"total" ,records:"records" ,repeatitems:false ,cell:"" ,id:"0" ,userdata:"" }, multiselect:false, autowidth:true, height:"auto", sortable:false, toppager:true, hidegrid: false, loadui: 'block', pager:"#grid_pager", caption: "Files", }); </code></pre> <p>A returned JSON request for the new folder looks something like this:</p> <pre><code>ret = {"error":"","total":1,"page":1,"records":1,"rows":[{"id":"1113","name":"test","uri":"accounting\/test\/","parent":1,"isLeaf":false,"expanded":true,"loaded":true}]} </code></pre> <p>Which I attempt to add in using:</p> <pre><code>grid[0].addJSONData(ret); </code></pre> <p>The initial data that is loaded is sent as JSON:</p> <pre><code>{"rows":[ {"id":"1","uri":"afolder\/","parent_id":"0","name":"afolder","level":0,"parent":"0","isLeaf":"false"}, {"id":"4","uri":"bfolder\/","parent_id":"0","name":"bfolder","level":0,"parent":"0","isLeaf":"false"}, {"id":"7","uri":"cfolder\/","parent_id":"0","name":"cfolder","level":0,"parent":"0","isLeaf":"false"}, {"id":"20","uri":"dfolder\/","parent_id":"0","name":"dfolder","level":0,"parent":"0","isLeaf":"false"}, {"id":"48","uri":"efolder\/","parent_id":"0","name":"efolder","level":0,"parent":"0","isLeaf":"false"}, {"id":"179","uri":"ffolder\/","parent_id":"0","name":"ffolder","level":0,"parent":"0","isLeaf":"false"}, {"id":"182","uri":"gfolder\/","parent_id":"0","name":"gfolder","level":0,"parent":"0","isLeaf":"false"}, {"id":"186","uri":"hfolder\/","parent_id":"0","name":"hfolder","level":0,"parent":"0","isLeaf":"false"}, {"id":"201","uri":"ifolder\/","parent_id":"0","name":"ifolder","level":0,"parent":"0","isLeaf":"false"}, {"id":"239","uri":"jfolder\/","parent_id":"0","name":"jfolder","level":0,"parent":"0","isLeaf":"false"}, {"id":"253","uri":"kfolder\/","parent_id":"0","name":"kfolder","level":0,"parent":"0","isLeaf":"false"}, {"id":"262","uri":"lfolder\/","parent_id":"0","name":"lfolder","level":0,"parent":"0","isLeaf":"false"}, {"id":"274","uri":"mfolder\/","parent_id":"0","name":"mfolder","level":0,"parent":"0","isLeaf":"false"} ]} </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. COAdding code is always very helpful, because it can get many additional important information. Could you describe more about the TreeGrid which you use. Do you use local data or load the data from the server. Do you load whole grid at once or you load child nodes on expanding its parent node? Which grid model you has: Nested Set Model or Adjacency Model. How you get information about the new Folder which should be added in the treegrid? Will be filled the information from some page input controls or if will be loaded from the server?
      singulars
    2. COWe use the adjacency model, and get the data in pieces as JSON requests from a MySQL Database as nodes are expanded. Information about the new folder is returned in a JSON request from creating the new folder record in the database via AJAX request. Added code.
      singulars
    3. COSorry, but I still not understand the situation. First you fill the tree grid with the data from the server. If the user click on the tree node the children of the node will be loaded from the server. How it come that one more node (folder) need be added? Why the data for the new folder contain a parent (`"parent":1`)? Probably the understanding how you fill the grid is connected to your main question. You wrote about getting "get the data in pieces", but from the database. I can't imagine such situation. If you make SELECT from the database you can send all results to the grid. Is it so?
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload