问题
I have this problem, treegrid in jqGrid ignores the last option (expanded node or not) when passing data through xml. Anyone encountered this? Is there a solution? Maybe its my data? Here is a sample data that produces the problem:
<rows>
<page>1</page>
<total>0</total>
<records>4</records>
<row id='2'>
<cell>2</cell>
<cell>Parent</cell>
<cell>0</cell>
<cell>NULL</cell>
<cell>false</cell>
<cell>true</cell>
</row>
<row id='1'>
<cell>1</cell>
<cell>Child 1</cell>
<cell>1</cell>
<cell>2</cell>
<cell>true</cell>
<cell>false</cell>
</row>
<row id='3'>
<cell>3</cell>
<cell>Child 2</cell>
<cell>1</cell>
<cell>2</cell>
<cell>true</cell>
<cell>false</cell>
</row>
<row id='4'>
<cell>4</cell>
<cell>Child 3</cell>
<cell>1</cell>
<cell>2</cell>
<cell>true</cell>
<cell>false</cell>
</row>
</rows>
回答1:
It seems for me more as a bug in TreeGrid. Nevertheless you can easy fix the problem by adding loaded: true
property to the node which need be expanded. The reason in the line of code and some above lines (see here) where loaded
property (and ldat[loaded]
) will be undefined
and so the ldat[expanded]
will be changed to undefined
for all items having no loaded
defined.
The demo demonstrate the solution. It uses XML which you posted but with additional <cell>true</cell>
added at the end of definition of "Parent"
item:
...
<row id='2'>
<cell>2</cell>
<cell>Parent</cell>
<cell>0</cell>
<cell>NULL</cell>
<cell>false</cell>
<cell>true</cell>
<cell>true</cell> <!-- added the element for loaded: true -->
</row>
...
UPDATED: I think that the most easy way to fix the bug (originally described here) will be to change the line of code setTreeNode
ldat[expanded] = ((ldat[expanded] == "true" || ldat[expanded] === true) ? true : false) &&
ldat[loaded];
to the following
ldat[expanded] = ((ldat[expanded] == "true" || ldat[expanded] === true) ? true : false) &&
(ldat[loaded] || ldat[loaded] === undefined);
See the corresponding demo used the fixed code.
来源:https://stackoverflow.com/questions/13195656/jqgrid-treegrid-ignores-expanded-state-when-provided-xml-data