Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>We solved this problem by extending the functionality of the jqGrid source. First we created a function that could delete all of the child nodes of a particular folder (both folders/branches and files/leaves), so that we could reload them and hence get the latest set of children. This function takes an integer <code>rowid</code> just like <code>delTreeNode()</code>.</p> <pre><code>delChildren : function (rowid) { return this.each(function () { var $t = this, rid = $t.p.localReader.id, left = $t.p.treeReader.left_field, right = $t.p.treeReader.right_field, myright, width, res, key; if(!$t.grid || !$t.p.treeGrid) {return;} var rc = $t.p._index[rowid]; if (rc !== undefined) { // nested myright = parseInt($t.p.data[rc][right],10); width = myright - parseInt($t.p.data[rc][left],10) + 1; var dr = $($t).jqGrid("getFullTreeNode",$t.p.data[rc]); if(dr.length&gt;0){ for (var i=0;i&lt;dr.length;i++){ if(dr[i][rid] != rowid) $($t).jqGrid("delRowData",dr[i][rid]); } } if( $t.p.treeGridModel === "nested") { // ToDo - update grid data res = $.jgrid.from($t.p.data) .greater(left,myright,{stype:'integer'}) .select(); if(res.length) { for( key in res) { res[key][left] = parseInt(res[key][left],10) - width ; } } res = $.jgrid.from($t.p.data) .greater(right,myright,{stype:'integer'}) .select(); if(res.length) { for( key in res) { res[key][right] = parseInt(res[key][right],10) - width ; } } } } }); }, </code></pre> <p>Then, we created a function to force reloading of a certain node (folder).</p> <pre><code>reloadNode: function(rc) { return this.each(function(){ if(!this.grid || !this.p.treeGrid) {return;} var rid = this.p.localReader.id; $(this).jqGrid("delChildren", rc[rid]); var expanded = this.p.treeReader.expanded_field, parent = this.p.treeReader.parent_id_field, loaded = this.p.treeReader.loaded, level = this.p.treeReader.level_field, lft = this.p.treeReader.left_field, rgt = this.p.treeReader.right_field; var id = $.jgrid.getAccessor(rc,this.p.localReader.id); var rc1 = $("#"+id,this.grid.bDiv)[0]; rc[expanded] = true; $("div.treeclick",rc1).removeClass(this.p.treeIcons.plus+" tree-plus").addClass(this.p.treeIcons.minus+" tree-minus"); this.p.treeANode = rc1.rowIndex; this.p.datatype = this.p.treedatatype; if(this.p.treeGridModel == 'nested') { $(this).jqGrid("setGridParam",{postData:{nodeid:id,n_left:rc[lft],n_right:rc[rgt],n_level:rc[level]}}); } else { $(this).jqGrid("setGridParam",{postData:{nodeid:id,parentid:rc[parent],n_level:rc[level]}} ); } $(this).trigger("reloadGrid"); rc[loaded] = true; if(this.p.treeGridModel == 'nested') { $(this).jqGrid("setGridParam",{postData:{nodeid:'',n_left:'',n_right:'',n_level:''}}); } else { $(this).jqGrid("setGridParam",{postData:{nodeid:'',parentid:'',n_level:''}}); } }); }, </code></pre> <p>This is the same as <code>expandNode()</code> save for that it does not check if the node was expanded to begin with, and forces it to send an AJAX request for the child elements of that node. This way, we always have the latest children.</p> <p>Finally, we fixed a small bug in <code>getRowData()</code>, which prevented us from using it to supply the <code>record</code> argument to either <code>expandNode()</code> or our newly created <code>reloadNode()</code>. The issue was that the <code>_id_</code> field in the JSON return was never created or filled. Adding that in fixed both <code>expandNode()</code> and <code>reloadNode()</code> The following is the changed source. Not ideal, but it works.</p> <pre><code>getRowData : function( rowid ) { var res = {}, resall, getall=false, len, j=0; this.each(function(){ var $t = this,nm,ind; if(typeof(rowid) == 'undefined') { getall = true; resall = []; len = $t.rows.length; } else { ind = $t.rows.namedItem(rowid); if(!ind) { return res; } len = 2; } while(j&lt;len){ if(getall) { ind = $t.rows[j]; } if( $(ind).hasClass('jqgrow') ) { $('td',ind).each( function(i) { nm = $t.p.colModel[i].name; if ( nm !== 'cb' &amp;&amp; nm !== 'subgrid' &amp;&amp; nm !== 'rn') { if($t.p.treeGrid===true &amp;&amp; nm == $t.p.ExpandColumn) { res[nm] = $.jgrid.htmlDecode($("span:first",this).html()); } else { if($t.p.colModel[i].key != undefined &amp;&amp; $t.p.colModel[i].key == true) { try { res["_" + nm + "_"] = $.unformat(this,{rowId:ind.id, colModel:$t.p.colModel[i]},i); } catch (e){ res["_" + nm + "_"] = $.jgrid.htmlDecode($(this).html()); } } try { res[nm] = $.unformat(this,{rowId:ind.id, colModel:$t.p.colModel[i]},i); } catch (e){ res[nm] = $.jgrid.htmlDecode($(this).html()); } } } }); if(getall) { resall.push(res); res={}; } } j++; } }); return resall ? resall: res; }, </code></pre> <p>Finally, we pull this all together as follows, with a JSON return object from creating a folder such as</p> <pre><code>{{"id":"1267", "name":"test15", "uri":"sample1\/test15\/", "parent_id":1, "parent":1, "isLeaf":false} </code></pre> <p>We call the function like</p> <pre><code>var parentid = ret.rows[0].parent; var parent = grid.jqGrid('getRowData', parentid); grid.jqGrid('reloadNode', parent); </code></pre> <p>The functions will delete all the child nodes of parent, then send an AJAX request for the new, updated list from the database. I'm going to push this onto the jqGrid Github if possible, since a <code>reload</code> function maybe useful for many people. I've posted it in here in case it isn't approved.</p>
    singulars
    1. This table or related slice is empty.
    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. This table or related slice is empty.
 

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