Quantcast
Channel: SmartClient Forums
Viewing all articles
Browse latest Browse all 4756

Sorting by an "undefined" property bug

$
0
0
Hello Isomorphic,

I think I found a bug when you group a ListGrid, because after the grouping is done a SortSpecifier with an "undefined" property is set on the resulting tree. And because SortSpecifiers are also propagated to the 'originalData' when invalidating the cache (please see DataBoundComponent.js#invalidateCache), such an 'undefined' sortBy property is also sent as a part of the fetch request.

Steps to reproduce:

1) Please go to your Showcase and choose "Live Grid" (http://www.smartclient.com/#fetchOperationFS)

2) Replace the code in the editor with this one:

Code:

isc.IButton.create({
  ID: "groupByBtn",
  autoDraw: false,
  width: 300,
  title: "1) Click here to group by category",
  click: function () { isc.say("After the grouping is done, the tree is gonna have a sort specifier set with an 'undefined' property.", function() { dsListGrid.groupBy("category"); }); }
});
isc.IButton.create({
  ID: "invalidateBtn",
  autoDraw: false,
  width: 300,
  title: "2) Once grouped click here to invalidate the cache",
  click: function () { isc.say("dsListGrid.data.getSort()[0].property: " + (dsListGrid.data.getSort()[0].property) + "<br/><br/>Please consult a network log to see &lt;sortBy xsi:type='xsd:List'&gt;&lt;elem&gt;undefined&lt;/elem&gt;&lt;/sortBy&gt; is sent", function() { dsListGrid.invalidateCache(); }); }
});

isc.ListGrid.create({
    autoDraw: false,
    ID:"dsListGrid",
    minFieldWidth:80,
    autoFetchData: true,
    dataSource: "supplyItem",
    groupByMaxRecords: Number.MAX_VALUE
});

isc.VLayout.create({
    ID: "layout",
    width: "100%",
    height: "100%",
    membersMargin: 10,
    members: [
        groupByBtn, invalidateBtn, dsListGrid
    ]
});

3) Click on the first button

4) Click on the second button

My suggestion (Version v10.0p_2014-12-10 (2014-12-10)):

Because Tree.js#getChildren calls sortByProperty()

Code:

...
getChildren : function (parentNode, displayNodeType, normalizer, sortDirection, criteria,
                        context, returnNulls, treatEmptyFoldersAsLeaves, dontUseNormalizer) {
   

    // If separateFolders is true, we need to have an openNormalizer so we can sort/separate
    // leaves and folders
    // This will not actually mark the tree as sorted by any property since we're not setting up
    // a sortProp.
   
    if (!dontUseNormalizer &&
        normalizer == null && this._openNormalizer == null && this.separateFolders)
    {
       
        if (this._sortSpecifiers != null) this.setSort(this._sortSpecifiers);
        else this.sortByProperty();
       
        normalizer = this._openNormalizer;
    }
...

and because sortByProperty() is defined as follows

Code:

sortByProperty : function (property, direction, normalizer, context) {
    if (!property && this.separateFolders == false) {
        // if we were called without a sort-property and this.sortProp is set, use it...
        if (this.sortProp) property = this.sortProp;
        else property = this.titleProperty;
    }
    if (!direction) direction = this.sortDirection;
    this.setSort([{
        property: property,
        direction: (isc.isA.String(direction) ? direction :
            (direction == true) ? "ascending" : "descending"),
        normalizer: normalizer,
        context: context
    }]);
}

I suggest making the setSort(...) call conditional:

Code:

sortByProperty : function (property, direction, normalizer, context) {
    if (!property && this.separateFolders == false) {
        // if we were called without a sort-property and this.sortProp is set, use it...
        if (this.sortProp) property = this.sortProp;
        else property = this.titleProperty;
    }
    if (!direction) direction = this.sortDirection;
    if(property) {
      this.setSort([{
          property: property,
          direction: (isc.isA.String(direction) ? direction :
              (direction == true) ? "ascending" : "descending"),
          normalizer: normalizer,
          context: context
      }]);
    }
}

Thank you and Best Regards

Dusan Kaloc

Viewing all articles
Browse latest Browse all 4756

Trending Articles