Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Terbeaux333 on Aug 12, 2009 15:46
open dhtmlx forum
TreeGrid ed[=sum] breaks on empty cell data

I have a TreeGrid initialized with the following column types.

myGrid.setColTypes("tree,ed[=sum],ed[=sum]")

If I load the 2nd or 3rd columns with no cell data, the cell reports "=sum" and the sum reports "NaN".
Rather the TreeGrid should interpret a no data cell as 0 when summing and display an empty cell.

Here's the xml to load into the above grid to reproduce this problem: (Column 1 of "Sub 1")

<rows>
<row id="totals" open="1" style="font-weight: bold;"><cell>Totals</cell>
<row id="1"><cell>Sub 1</cell><cell type="edn"></cell><cell type="edn">10</cell></row>
<row id="2"><cell>Sub 2</cell><cell type="edn">20</cell><cell type="edn">10</cell></row>
<row id="3"><cell>Sub 3</cell><cell type="edn">20</cell><cell type="edn">10</cell></row>
</row>
</rows>

Thanks,

Terbeaux333
Answer posted by dhxSupport on Aug 13, 2009 07:26
To fix this issue you can do the following:
set default value for the 2nd and 3rd columns:
mygrid.setColTypes("tree,ed[0],ed[0]")

Define 2nd and 3rd cell's types at the parent row via xml:
<rows> 
<row id="totals" open="1" style="font-weight: bold;">
<cell>Totals</cell> 
 <row id="1"><cell>Sub 1</cell><cell type="edn"></cell><cell type="edn">10</cell></row> 
 <row id="2"><cell>Sub 2</cell><cell type="edn">20</cell><cell type="edn">10</cell></row> 
 <row id="3"><cell>Sub 3</cell><cell type="edn">20</cell><cell type="edn">10</cell></row> 
<cell type="math">=sum</cell>
<cell type="math">=sum</cell>

</row> 
</rows>


Answer posted by Terbeaux333 on Aug 13, 2009 08:23
Most excellent.  Your solution worked well.  However, after you guys led me down the right path, I found it better to do the following:

myGrid.setColTypes("tree,ed,ed")   // No default specified

Then with my data, provide the following.

<rows> 
  <row id="totals" open="1" style="font-weight: bold;">
  <cell>Totals</cell>
<cell type="math">=sum</cell><cell type="math">=sum</cell>
    <row id="1"><cell>Sub 1</cell><cell></cell><cell>10</cell></row> 
    <row id="2"><cell>Sub 2</cell><cell>20</cell><cell>10</cell></row> 
    <row id="3"><cell>Sub 3</cell><cell>20</cell><cell>10</cell></row> 
</row> 
</rows>


This gave me the ability to have <blank> cells and still have my summation work properly.

Thanks a bunch guys!!

Terbeaux333