1. #1
    Sencha Premium Member rpiwonka's Avatar
    Join Date
    Jul 2007
    Posts
    29
    Vote Rating
    0
    rpiwonka is on a distinguished road

      0  

    Default Ext.ux.grid.plugin.RowSelectionPaging upgraded to 4.1

    Ext.ux.grid.plugin.RowSelectionPaging upgraded to 4.1


    This plugin is completely based on Ext.ux.grid.RowSelectionPaging, a 3.x plugin by Joeri Sebrechts, and is used to maintain the selection state of rows in a paginated Grid Panel when moving between pages. This is tested in Ext 4.1.0.

    I have only made the necessary modifications to make it work. All credit should be directed at the original author, this post is for the benefit of people that need to upgrade to 4.1 and already utilize this plugin.

    Enjoy.

    Code:
    Ext.define('Ext.ux.grid.plugin.RowSelectionPaging',
    {
    	extend: 'Ext.AbstractPlugin',
    	alias: 'plugin.rowselectionpaging',
    	pluginId: 'rowselectionpaging',
    	selections: [],
    	selected: {},
    	init: function (grid)
    	{
    		this.grid = grid;
    		grid.on('render', function ()
    		{
    			// attach an interceptor for the selModel's onRefresh handler
    			this.grid.view.un('refresh', this.grid.selModel.refresh, this.grid.selModel);
    			this.grid.view.on('refresh', this.onViewRefresh, this);
    
    			// add a handler to detect when the user changes the selection
    			this.grid.selModel.on('select', this.onRowSelect, this);
    			this.grid.selModel.on('deselect', this.onRowDeselect, this);
    
    			// patch selModel to detect selection cleared events
    			var scope = this;
    			this.selModelClearSelections = this.grid.selModel.deselectAll;
    			this.grid.selModel.deselectAll = function (fast)
    			{
    				scope.selModelClearSelections.call(this, fast);
    				scope.onSelectionClear();
    			};
    			if (this.grid.selModel.mode == 'SINGLE')
    			{
    				this.grid.selModel.mode = 'SIMPLE'; //why would you want to hold multiple selections in single select mode ?
    			}
    			// and replace the default behavior of the "check all"
    			if (!this.originalSelectAll && (this.grid.selModel.alias[0] == 'selection.checkboxmodel'))
    			{
    				this.grid.selModel.onHeaderClick = function (headerCt, header, e)
    				{
    					if (header.isCheckerHd)
    					{
    						e.stopEvent();
    						var me = this,
    						isChecked = header.el.hasCls(me.checkerOnCls);
    
    						// Prevent focus changes on the view, since we're selecting/deselecting all records
    						me.preventFocus = true;
    						if (isChecked)
    						{
    							//me.deselectAll();
    							scope.clearSelections();
    						} else
    						{
    							//me.selectAll();
    							scope.selectAll();
    						}
    						me.toggleUiHeader(!isChecked);
    						delete me.preventFocus;
    					}
    				};
    			}
    		}, this);
    	}, // end init
    
    	// private
    	onViewRefresh: function ()
    	{
    		this.ignoreSelectionChanges = true;
    		// explicitly refresh the selection model
    		this.grid.selModel.refresh();
    		// selection changed from view updates, restore full selection
    		var ds = this.grid.getStore();
    		var newSel = [];
    		for (var i = ds.getCount() - 1; i >= 0; i--)
    		{
    			if ((this.isSelectAll() && this.selected[ds.getAt(i).id] !== false) || this.selected[ds.getAt(i).id])
    			{
    				newSel.push(ds.getAt(i));
    			}
    		}
    		this.grid.selModel.select(newSel, false);
    		this.ignoreSelectionChanges = false;
    	}, // end onViewRefresh
    
    	// private
    	onSelectionClear: function ()
    	{
    		if (!this.ignoreSelectionChanges)
    		{
    			// selection cleared by user
    			// also called internally when the selection replaces the old selection
    			this.selections = [];
    			this.selected = {};
    		}
    	}, // end onSelectionClear
    
    	// private
    	onRowSelect: function (sm, rec, i, eOpts)
    	{
    		if (!this.ignoreSelectionChanges)
    		{
    			if (!this.selected[rec.id])
    			{
    				this.selected[rec.id] = true;
    			}
    		}
    	}, // end onRowSelect
    
    	// private
    	onRowDeselect: function (sm, rec, i, eOpts)
    	{
    		if (!this.ignoreSelectionChanges)
    		{
    			this.selected[rec.id] = false;
    		}
    	}, // end onRowDeselect
    
    	/**
    	* Clears selections across all pages
    	*/
    	clearSelections: function ()
    	{
    		this.selections = [];
    		this.selected = {};
    		this.onViewRefresh();
    	}, // end clearSelections
    
    	/**
    	* Returns the selected records for all pages
    	* @return {Array} Array of selected records
    	*/
    	getSelections: function ()
    	{
    		//return [].concat(this.selections);
    		return this.selected;
    	}, // end getSelections
    	isSelectAll: function ()
    	{
    		return this.selected["ALL"] === true;
    	},
    	getSelectionCount: function ()
    	{
    		if (this.isSelectAll())
    		{
    			var ds = this.grid.getStore();
    			var notSelCnt = 0;
    			for (prop in this.selected)
    			{
    				if (this.selected[prop] === false)
    				{
    					notSelCnt++;
    				}
    			}
    			return ds.getTotalCount() - notSelCnt;
    		}
    		else
    		{
    			var selCnt = 0;
    			for (prop in this.selected)
    			{
    				if (this.selected[prop] === true)
    				{
    					selCnt++;
    				}
    			}
    			return selCnt;
    		}
    	},
    	selectAll: function ()
    	{
    		this.selected = {};
    		this.selected["ALL"] = true;
    		this.onViewRefresh();
    		return;
    	}
    });

  2. #2
    Sencha Premium Member harrydeluxe's Avatar
    Join Date
    Jul 2007
    Location
    Nürnberg, Germany
    Posts
    78
    Vote Rating
    29
    harrydeluxe has a spectacular aura about harrydeluxe has a spectacular aura about

      0  

    Default


    Thank you for the contribution! I like this extension.
    DELACAP | Github
    "don't code today what you can't debug tomorrow"

Thread Participants: 1

Tags for this Thread

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar