All files / dgrid/extensions SingleQuery.js

0% Statements 0/22
0% Branches 0/4
0% Functions 0/7
0% Lines 0/22

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64                                                                                                                               
define([
	'dojo/_base/declare',
	'dojo/dom-construct',
	'../_StoreMixin'
], function (declare, domConstruct, _StoreMixin) {
	return declare(_StoreMixin, {
		// summary:
		//		dgrid mixin which implements the refresh method to
		//		always perform a single query with no start or count
		//		specified, to retrieve all relevant results at once.
		//		Appropriate for grids using memory stores with small
		//		result set sizes.
 
		refresh: function () {
			var self = this;
 
			// First defer to List#refresh to clear the grid's
			// previous content
			this.inherited(arguments);
 
			if (!this._renderedCollection) {
				return;
			}
 
			return this._trackError(function () {
				var loadingNode = self.loadingNode = domConstruct.create('div', {
					className: 'dgrid-loading',
					innerHTML: self.loadingMessage
				}, self.contentNode);
 
				var queryResults = self._renderedCollection.fetch();
 
				queryResults.totalLength.then(function (total) {
					// Record total so it can be retrieved later via get('total')
					self._total = total;
 
					if (!total) {
						self._insertNoDataNode();
					}
				});
 
				queryResults.always(function () {
					domConstruct.destroy(loadingNode);
					self.loadingNode = null;
				});
 
				return self.renderQueryResults(queryResults).then(function (rows) {
					self._emitRefreshComplete();
					return rows;
				});
			});
		},
 
		renderArray: function () {
			var rows = this.inherited(arguments);
 
			// Clear _lastCollection which is ordinarily only used for store-less grids
			this._lastCollection = null;
 
			return rows;
		}
	});
});