Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem weird sorting while adding elements dynamically to tree for display in dgrid #150

Open
GuiguiZ opened this issue Aug 12, 2015 · 0 comments

Comments

@GuiguiZ
Copy link

GuiguiZ commented Aug 12, 2015

hi
I think I found a bug on the framework, I just wanted a confirmation
I'm using dgrid with a tree architecture
and while adding elements to subnodes, I got some weird sorting after inserting a certain number of elements.

Here is the way I did my insertions:

    updateCharges:function(path){
        var pathArr = path.split(":");
        page.grid.set('collection',null);
    //Bien.get(pathArr[0]) returns the array with the elements contained by the node whose name is the value contained in pathArr[0]
    //_id is the identifier of my collection
        Bien.get(pathArr[0]).forEach(function(field,index){
            var isRemoved=Bien.getRemoved(pathArr[0]+':'+index);
            field._id=pathArr[0]+"_"+index;
            field.id=index;
            if(isRemoved===true){
                page.collec.remove(field._id);
            }
            else{
                page.collec.put(lang.mixin({parent:pathArr[0],hasChildren:false,path:pathArr[0]+':'+index,editable:true},field));
            }


        });
        page.grid.set('collection',page.collec);
    }

page.collec is created this way:

page.collec=createHierarchicalStore({ data: this.baseData }, false);

with the createHierarchicalStore given in dgrid/test/data (not modified)

after a few nights of struggle I eventually found out approximately the way it worked.
It appears that there are 3 "queryMethods" , or 3 entries in the "querylog" variable, i must admit this remains mostly unclear for me
anyway, i understood that 1 is filtering by parent, the second sorting by id
and the 3rd is mysteriously an empty array
in theory it shouldnt have been a problem, since in the _createSortQuerier of "SimpleQuery", it is specified to return '0' on the compare function of "data.sort" in case of empty array,
but for some reason, data changes after the call to sort
even tough the compare function is returning 0.
if added this line in the beginning of _createSortQuerier:

    _createSortQuerier: function (sorted) {
        var queryAccessors = this.queryAccessors;
        return function (data) {
                            //debut solution brutale
            if(sorted.length===0 && typeof sorted != 'function'){
                return data;
            }
    [...]

and the problem disappears.
But I cannot find out why is this 3rd entry in the qerylog array present, and last but not least, I cannot find out in dgrid nor in dstore code where this is added
so if somebody can light my candle it'd be great, because the solution I found smells like a workaround.

Cheers

Guillaume

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants