data-grouping-debug.js
上传用户:dawnssy
上传日期:2022-08-06
资源大小:9345k
文件大小:5k
源码类别:

JavaScript

开发平台:

JavaScript

  1. /*!  * Ext JS Library 3.1.0  * Copyright(c) 2006-2009 Ext JS, LLC  * licensing@extjs.com  * http://www.extjs.com/license  */ /**
  2.  * @class Ext.data.GroupingStore
  3.  * @extends Ext.data.Store
  4.  * A specialized store implementation that provides for grouping records by one of the available fields. This
  5.  * is usually used in conjunction with an {@link Ext.grid.GroupingView} to proved the data model for
  6.  * a grouped GridPanel.
  7.  * @constructor
  8.  * Creates a new GroupingStore.
  9.  * @param {Object} config A config object containing the objects needed for the Store to access data,
  10.  * and read the data into Records.
  11.  * @xtype groupingstore
  12.  */
  13. Ext.data.GroupingStore = Ext.extend(Ext.data.Store, {
  14.     
  15.     //inherit docs
  16.     constructor: function(config){
  17.         Ext.data.GroupingStore.superclass.constructor.call(this, config);
  18.         this.applyGroupField();
  19.     },
  20.     
  21.     /**
  22.      * @cfg {String} groupField
  23.      * The field name by which to sort the store's data (defaults to '').
  24.      */
  25.     /**
  26.      * @cfg {Boolean} remoteGroup
  27.      * True if the grouping should apply on the server side, false if it is local only (defaults to false).  If the
  28.      * grouping is local, it can be applied immediately to the data.  If it is remote, then it will simply act as a
  29.      * helper, automatically sending the grouping field name as the 'groupBy' param with each XHR call.
  30.      */
  31.     remoteGroup : false,
  32.     /**
  33.      * @cfg {Boolean} groupOnSort
  34.      * True to sort the data on the grouping field when a grouping operation occurs, false to sort based on the
  35.      * existing sort info (defaults to false).
  36.      */
  37.     groupOnSort:false,
  38. groupDir : 'ASC',
  39.     /**
  40.      * Clears any existing grouping and refreshes the data using the default sort.
  41.      */
  42.     clearGrouping : function(){
  43.         this.groupField = false;
  44.         if(this.remoteGroup){
  45.             if(this.baseParams){
  46.                 delete this.baseParams.groupBy;
  47.             }
  48.             var lo = this.lastOptions;
  49.             if(lo && lo.params){
  50.                 delete lo.params.groupBy;
  51.             }
  52.             this.reload();
  53.         }else{
  54.             this.applySort();
  55.             this.fireEvent('datachanged', this);
  56.         }
  57.     },
  58.     /**
  59.      * Groups the data by the specified field.
  60.      * @param {String} field The field name by which to sort the store's data
  61.      * @param {Boolean} forceRegroup (optional) True to force the group to be refreshed even if the field passed
  62.      * in is the same as the current grouping field, false to skip grouping on the same field (defaults to false)
  63.      */
  64.     groupBy : function(field, forceRegroup, direction){
  65. direction = direction ? (String(direction).toUpperCase() == 'DESC' ? 'DESC' : 'ASC') : this.groupDir;
  66.         if(this.groupField == field && this.groupDir == direction && !forceRegroup){
  67.             return; // already grouped by this field
  68.         }
  69.         this.groupField = field;
  70. this.groupDir = direction;
  71.         this.applyGroupField();
  72.         if(this.groupOnSort){
  73.             this.sort(field, direction);
  74.             return;
  75.         }
  76.         if(this.remoteGroup){
  77.             this.reload();
  78.         }else{
  79.             var si = this.sortInfo || {};
  80.             if(si.field != field || si.direction != direction){
  81.                 this.applySort();
  82.             }else{
  83.                 this.sortData(field, direction);
  84.             }
  85.             this.fireEvent('datachanged', this);
  86.         }
  87.     },
  88.     
  89.     // private
  90.     applyGroupField: function(){
  91.         if(this.remoteGroup){
  92.             if(!this.baseParams){
  93.                 this.baseParams = {};
  94.             }
  95.             this.baseParams.groupBy = this.groupField;
  96.             this.baseParams.groupDir = this.groupDir;
  97.         }
  98.     },
  99.     // private
  100.     applySort : function(){
  101.         Ext.data.GroupingStore.superclass.applySort.call(this);
  102.         if(!this.groupOnSort && !this.remoteGroup){
  103.             var gs = this.getGroupState();
  104.             if(gs && (gs != this.sortInfo.field || this.groupDir != this.sortInfo.direction)){
  105.                 this.sortData(this.groupField, this.groupDir);
  106.             }
  107.         }
  108.     },
  109.     // private
  110.     applyGrouping : function(alwaysFireChange){
  111.         if(this.groupField !== false){
  112.             this.groupBy(this.groupField, true, this.groupDir);
  113.             return true;
  114.         }else{
  115.             if(alwaysFireChange === true){
  116.                 this.fireEvent('datachanged', this);
  117.             }
  118.             return false;
  119.         }
  120.     },
  121.     // private
  122.     getGroupState : function(){
  123.         return this.groupOnSort && this.groupField !== false ?
  124.                (this.sortInfo ? this.sortInfo.field : undefined) : this.groupField;
  125.     }
  126. });
  127. Ext.reg('groupingstore', Ext.data.GroupingStore);