Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by n.darques on Jun 02, 2008 10:17
open dhtmlx forum
[TREEGRID] coro[=sum] column can't be edited

In a treegrid with smartXMLparsing disables, I have a row with severals subrows.
One column of this treegrid is set as a "coro[=sum]".
The combo box is filled with this script :

    var combo = mygrid.getCombo(1);
    combo.put("0.25","0.25");
    combo.put("0.50","0.50");
    combo.put("1.00","1.00");

the treegrid init is done by loading an XML with contains values formatted like that for each row:

<row id="711">
<cell image="leaf.gif">2008-06-02</cell>
<cell>0.50</cell>
...

Everything seems to works fine, until you try to edit this column : No edit event seems to be launched (other columns works).
If you set this column to "coro", editing works fine but, of course, sum of subrows doesn't work anymore.

Any thought ?
Answer posted by Support on Jun 03, 2008 01:47
The cell in grid can be
a) normal editable cell
b) cell, which value calculated by math

It not possible to combine both functionalities for the same cell, because cell can't allow direct input and show result according assigned math formula in same time.

In described situation you can define whole column as math, and mark cells, which is "coro" directly in XML

<row id="711">
<cell image="leaf.gif">2008-06-02</cell>
<cell type="coro">0.50</cell>

Please check attached sample, the third column in it also defined as =sum but last level elements described in XML as editable - as result the sum functionality works for folders, and leaf items editable in the same time.
Attachments (1)
Answer posted by n.darques on Jun 03, 2008 04:21
Thanks for your quick input.
Setting each cell as "coro" corrects my issue.

However, I still have a last issue.
When adding or deleting a subrow (script command driven by a context-menu), row sum doesn't refresh accordingly.
For now, refresh seems to be only called on edit of a cell of a subrow.
Any way to force sum update  ?

Migrating from 1.5 to 1.6 is not such a easy operation, aftter all ;)
Attachments (2)
Answer posted by Support on Jun 03, 2008 05:22
The =sum calculation works fine for newly added rows in local tests, but if you are using both in-line and sum math formulas the problem really may occur.
Please try to use attached js file instead of original one - it must correctly process math formulas in newly added rows ( the online package will be updated with the same fix in nearest time )

>>Any way to force sum update  ?
There is no special API for such case, but if you need to force the "=sum" formulas, you can use
    grid.callEvent("onXLS",[]);
beware that it will trigger any custom onXLS code as well.
Attachments (1)
Answer posted by n.darques on Jun 03, 2008 05:51
>> Please try to use attached js file instead of original one
Tried. Doesn't fix the problem.
After a brief look at 'ext/dhtmlxgrid_math.js', I notice this part in the 'constructor' :

this.attachEvent("onClearAll",function(){
        this._mat_links={};
        this._aggregators=[];
    })
this.attachEvent("onCellChanged",function(id,ind){

        if (this._mat_links[id]){
            var cell=this._mat_links[id][ind]
            if (cell){
                this.cells5(cell).setValue(this._calcSCL(cell));
            }
        }
        if (!this._parsing && this._aggregators[ind]){
            var pid=this._h2.get[id].parent.id;
            if (pid!=0){
                var ed=this.cells(pid,ind);
                ed.setValue(this._calcSCL(ed.cell));
            }
        }
    })
    this.attachEvent("onXLE",function(){
        for (var i=0; i < this._aggregators.length; i++) {
            if (this._aggregators[i])
                this._h2.forEachChild(0,function(el){
                    if (el.childs.length!=0){
                        var ed=this.cells(el.id,i);
                        ed.setValue(this._calcSCL(ed.cell));
                    }
                },this);
        };




Sorry if it's not relevant but it maybe come from here as only loading,unloading and editcell events are covered ?


 >> grid.callEvent("onXLS",[]);
>> beware that it will trigger any custom onXLS code as well.
I will try this workaround if no other solution arises as I have to rewrite a good piece of my code to bypass functions called at XLS event.
Answer posted by n.darques on Jun 03, 2008 06:02
Just try for debug to put this code after adding/deleting a row :
grid.callEvent("onXLE",[]);
It actually forces the refresh which seems to validate my previous assertion.

For information,
grid.callEvent("onXLS",[]);
doesn't seem to update sum.

Answer posted by Support on Jun 03, 2008 10:31
The math done through onCellChanged event - this event triggered for ALL operation which change cell values ( any API call which change cell value will trigger it, not only edit operations)
When row created - this event will fire for each cell in row, and if any of it contains the math - it will trigger calculations ( the updated js file attached to previous post resolves issue with row registration, so on moment of data filling it is available to API calls )

With latest version of js file - the math works correctly against for newly added rows ( both per column sum and per row operations ) - I can send a sample if necessary.
Can it be that some custom excell type used in your case?
Answer posted by Support on Jun 03, 2008 10:27
>>doesn't seem to update sum.
This was a typo from our side, sorry for inconvenience
Answer posted by n.darques on Jun 04, 2008 05:58
As it seems that my issue is probably due to a bad mix of several features mixed together, I've tried to produce a minimalist sample (stripped down from my application).
You'll find in attachment a standalone sample that demonstrate my issue.

Please note thoses commented line :
line 317 : mygrid.cellById(timestamp,1).setValue("1.00"); //HACK HAVE TO RESET VALUE AS ADDROW DOESN'T WORK PROPERLY
line 327 : mygrid.callEvent("onXLE",[]);  // HACK FORCE SUM REFRESH
line 334 : mygrid.callEvent("onXLE",[]); // HACK FORCE SUM REFRESH

For now, I have to seperate issue in this sample :
1- AddRow method doesnt' work properly as It doesn't set value for column 1
2- Sum is not updated when adding Row ou deleting Row.

P.S. : Sample attachment could be removed as soon as you took it.

Answer posted by Support on Jun 05, 2008 08:15
There was a tricky bug related to usage of coro_excell as math based in treegrid
Fixed files sent by email.
Answer posted by n.darques on Jun 06, 2008 03:47
Fixes tested.
It Corrects issues but seems to create a new one.

It might be in the chain of events, as some are triggered with delay.
When I delete or add a row, I put in my custom code a refresh global sum function
Sample code :

switch(menuitemId) {
            case "addRow":
                // CODE FOR ADDING SUB ROW ....//

                calculateFooterValues(); // Update footer Values (sum of rows)

            break;
           
            case "removeRow" :
                // CODE FOR DELETING SUB ROW ....//

                calculateFooterValues(); //Update footer Values (sum of rows)
            break;
}


Thing is that when I add a row, 'calculateFooterValues' is called AFTER update of the row (that is to say Math calculation of the sum of all subrows), although when I delete a row, 'calculateFooterValues' is called BEFORE  update of the row and thus doesn't update of correct value.

According to me,the most elegant way of correcting this issue would be to use a event called when all maths calculations are done. However, after scooping your code quickly, no event of this kind seems to exist.
Any idea ?

Answer posted by Support on Jun 06, 2008 05:51
Yes, the problem caused by the way how math recalculated after row deleting, while all other math recalculated in sync mode - this part done in async. way, which cause problems with custom code.
The code adjusted to work correctly. Fixed files sent by email.
Answer posted by n.darques on Jun 06, 2008 05:53
Just found out Aggregation in TreeGrid feature.
That's perfect for my needs. I just replace my calculateFooterValues() function by {#stat_tree_total_leaf} in the attached footer.
Unfortunatly, adding a row produces now a error :
row has no properties
(breakpoint : if (row._locator){
http://enet-dev/LIB/JAVASCRIPT/DHTMLX/dhtmlxGrid/sources/dhtmlxgrid.js
Line 5312 )

Answer posted by Support on Jun 06, 2008 06:05
Fixed "stat and filter in treegrid" extension attached
Attachments (1)
Answer posted by n.darques on Jun 06, 2008 07:01
Tried out fixed "stat and filter in treegrid" extension which corrects my previous error.

However, for the sake of getting last fix for each issue, I didn't received by email fixed code for async delete issue.

Furthermore, I just noticed (It might be linked) that if I create several subrows and  delete one, everything seems ok. (dataprocessor installed with autoUpdate off)
When I send data (mydataprocessor.sendData() ), the deleted subrow remains in treegrid (text style no more in bold but still with a strike line).
A full reload of the page confirms that this row still exists in database.
A detailed inquiry of the ajax action shows that sometimes url sent is not what you could expect :
gridUpdate.php?gr_id=1212760077757&gr_pid=day%7C2008-06-04&c0=2008-06-04&c1=1.00&c2=day&c3=1&c4=3&c5=5&c6=13&!nativeeditor_status=inserted // CORRECT (new subrow as id could confirm)
gridUpdate.php?gr_id=778&gr_pid=day%7C2008-06-04&c0=2008-06-04&c1=0.25&c2=day&c3=1&c4=3&c5=5&c6=13&!nativeeditor_status=inserted // INCORRECT should be 'deleted'

Sorry for all thoses issues adressed in such a short time ;)
Answer posted by Support on Jun 06, 2008 09:50
Possible solution send by email.
Answer posted by n.darques on Jun 09, 2008 01:20
I just realized that I might have mispelled my email.
Take note that  first part is 'ndarques' and not 'n.darques'.
Sorry for that.
Answer posted by Support on Jun 09, 2008 04:57
We have send all fixed files to correct email address.
Answer posted by n.darques on Jun 09, 2008 07:08
Last fix tested. It corrects every last flaws.
Thanks for you extra support which, as ever, rocks !