dojox/grid/enhanced/plugins/_RowMapLayer.js

  • Provides:

    • dojox.grid.enhanced.plugins._RowMapLayer
  • Requires:

    • dojox.grid.enhanced.plugins._StoreLayer in common
  • dojox.grid.enhanced.plugins._RowMapLayer

    • type
      Function
    • chains:
      • dojox.grid.enhanced.plugins._StoreLayer: (prototype)
      • dojox.grid.enhanced.plugins._StoreLayer: (call)
      • _this._oldOnDelete: (call)
      • _this._oldSort: (call)
    • parameters:
      • grid: (typeof )
    • source: [view]
        this._map = {};
        this._revMap = {};
        this.grid = grid;
        this._oldOnDelete = grid._onDelete;
        var _this = this;
        grid._onDelete = function(item){
         _this._onDelete(item);
         _this._oldOnDelete.call(grid, item);
        };
        this._oldSort = grid.sort;
        grid.sort = function(){
         _this.clearMapping();
         _this._oldSort.apply(grid, arguments);
        };
    • summary
  • dojox.grid.enhanced.plugins._RowMapLayer.tags

    • summary
  • dojox.grid.enhanced.plugins._RowMapLayer.uninitialize

    • type
      Function
    • source: [view]
        this.grid._onDelete = this._oldOnDelete;
        this.grid.sort = this._oldSort;
    • summary
  • dojox.grid.enhanced.plugins._RowMapLayer.setMapping

    • type
      Function
    • parameters:
      • mapping: (typeof Object)
        keys are original rowIndexes, values are new rowIndexes.
    • source: [view]
        this._store.forEachLayer(function(layer){
         if(layer.name() === "rowmap"){
          return false;
         }else if(layer.onRowMappingChange){
          layer.onRowMappingChange(mapping);
         }
         return true;
        }, false);
        var from, to, origin, revmap = {};
        for(from in mapping){
         from = parseInt(from, 10);
         to = mapping[from];
         if(typeof to == "number"){
          if(from in this._revMap){
           origin = this._revMap[from];
           delete this._revMap[from];
          }else{
           origin = from;
          }
          if(origin == to){
           delete this._map[origin];
           revmap[to] = "eq";
          }else{
           this._map[origin] = to;
           revmap[to] = origin;
          }
         }
        }
        for(to in revmap){
         if(revmap[to] === "eq"){
          delete this._revMap[parseInt(to, 10)];
         }else{
          this._revMap[parseInt(to, 10)] = revmap[to];
         }
        }
    • summary
      Remember the row mapping.
  • dojox.grid.enhanced.plugins._RowMapLayer.clearMapping

    • type
      Function
    • source: [view]
        this._map = {};
        this._revMap = {};
    • summary
  • dojox.grid.enhanced.plugins._RowMapLayer._onDelete

    • type
      Function
    • parameters:
      • item: (typeof )
    • source: [view]
        var idx = this.grid._getItemIndex(item, true);
        if(idx in this._revMap){
         var rowIdxArr = [], r, i, origin = this._revMap[idx];
         delete this._map[origin];
         delete this._revMap[idx];
         for(r in this._revMap){
          r = parseInt(r, 10);
          if(this._revMap[r] > origin){
           --this._revMap[r];
          }
         }
         for(r in this._revMap){
          r = parseInt(r, 10);
          if(r > idx){
           rowIdxArr.push(r);
          }
         }
         rowIdxArr.sort(function(a, b){
          return b - a;
         });
         for(i = rowIdxArr.length - 1; i >= 0; --i){
          r = rowIdxArr[i];
          this._revMap[r - 1] = this._revMap[r];
          delete this._revMap[r];
         }
         this._map = {};
         for(r in this._revMap){
          this._map[this._revMap[r]] = r;
         }
        }
    • summary
  • dojox.grid.enhanced.plugins._RowMapLayer._fetch

    • type
      Function
    • parameters:
      • userRequest: (typeof )
    • source: [view]
        var mapCount = 0, r;
        var start = userRequest.start || 0;
        for(r in this._revMap){
         r = parseInt(r, 10);
         if(r >= start){
          ++mapCount;
         }
        }
        if(mapCount > 0){
         //Row mapping is in use.
         var rows = [], i, map = {},
          count = userRequest.count > 0 ? userRequest.count : -1;
         if(count > 0){
          for(i = 0; i < count; ++i){
           r = start + i;
           r = r in this._revMap ? this._revMap[r] : r;
           map[r] = i;
           rows.push(r);
          }
         }else{
          //We don't have a count, must create our own.
          for(i = 0;; ++i){
           r = start + i;
           if(r in this._revMap){
            --mapCount;
            r = this._revMap[r];
           }
           map[r] = i;
           rows.push(r);
           if(mapCount <= 0){
            break;
           }
          }
         }
         this._subFetch(userRequest, this._getRowArrays(rows), 0, [], map, userRequest.onComplete, start, count);
         return userRequest;
        }else{
         //No row mapping at all.
         return dojo.hitch(this._store, this._originFetch)(userRequest);
        }
    • summary
  • dojox.grid.enhanced.plugins._RowMapLayer._getRowArrays

    • type
      Function
    • parameters:
      • rows: (typeof )
    • source: [view]
        return _devideToArrays(rows);
    • summary
  • dojox.grid.enhanced.plugins._RowMapLayer._subFetch

    • type
      Function
    • parameters:
      • userRequest: (typeof )
      • rowArrays: (typeof )
      • index: (typeof )
      • result: (typeof )
      • map: (typeof )
      • oldOnComplete: (typeof )
      • start: (typeof )
      • count: (typeof )
    • source: [view]
        var arr = rowArrays[index], _this = this;
        var urstart = userRequest.start = arr[0];
        userRequest.count = arr[arr.length - 1] - arr[0] + 1;
        userRequest.onComplete = function(items){
         dojo.forEach(items, function(item, i){
          var r = urstart + i;
          if(r in map){
           result[map[r]] = item;
          }
         });
         if(++index == rowArrays.length){
          //mapped rows are all fetched.
          if(count > 0){
           userRequest.start = start;
           userRequest.count = count;
           userRequest.onComplete = oldOnComplete;
           hitchIfCan(userRequest.scope, oldOnComplete)(result, userRequest);
          }else{
           userRequest.start = userRequest.start + items.length;
           delete userRequest.count;
           userRequest.onComplete = function(items){
            result = result.concat(items);
            userRequest.start = start;
            userRequest.onComplete = oldOnComplete;
            hitchIfCan(userRequest.scope, oldOnComplete)(result, userRequest);
           };
           _this.originFetch(userRequest);
          }
         }else{
          _this._subFetch(userRequest, rowArrays, index, result, map, oldOnComplete, start, count);
         }
        };
        _this.originFetch(userRequest);
    • summary
  • dojox.grid.enhanced.plugins._RowMapLayer.grid._onDelete

    • summary
  • dojox.grid.enhanced.plugins._RowMapLayer.grid.sort

    • summary
  • dojox.grid.enhanced.plugins._RowMapLayer._map

    • summary
  • dojox.grid.enhanced.plugins._RowMapLayer._revMap

    • summary
  • dojox.grid.enhanced.plugins._RowMapLayer.grid

    • summary
  • dojox.grid.enhanced.plugins._RowMapLayer._oldOnDelete

    • summary
  • dojox.grid.enhanced.plugins._RowMapLayer._oldSort

    • summary
  • hitchIfCan

    • type
      Function
    • parameters:
      • scope: (typeof )
      • func: (typeof )
    • source: [view]
       return func ? dojo.hitch(scope || dojo.global, func) : function(){};
    • summary
  • dojox.grid.enhanced.plugins

    • type
      Object
    • summary
  • dojox.grid.enhanced

    • type
      Object
    • summary
  • dojox.grid

    • type
      Object
    • summary
  • dojox

    • type
      Object
    • summary