Note that there are some explanatory texts on larger screens.

plurals
  1. POAdd new rows to jqGrid Treegrid model
    text
    copied!<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>
 

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