jsxgrid 2.3.1 → 2.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,11 @@
1
- (function(jsGrid, $, undefined) {
2
-
3
- if (!jsGrid) {
4
- if (window.console) {
5
- console.error("[jsxgrid] jsgrid.field.Xselect.js was loaded before the jsxgrid engine (jsxgrid.js) - include the engine first.");
6
- }
7
- return;
8
- }
1
+ (function(jsGrid, $, undefined) {
2
+
3
+ if (!jsGrid) {
4
+ if (window.console) {
5
+ console.error("[jsxgrid] jsgrid.field.Xselect.js was loaded before the jsxgrid engine (jsxgrid.js) - include the engine first.");
6
+ }
7
+ return;
8
+ }
9
9
 
10
10
 
11
11
  // Standalone: does not extend jsGrid.SelectField, only jsGrid.Field.
@@ -35,7 +35,8 @@
35
35
  valueType: NUMBER_VALUE_TYPE,
36
36
  pseudoElement: null,//pseudoElement that will be unsifted to start of select data in filters
37
37
  select2: null,
38
- defaultSelected: null,
38
+ defaultSelected: null,//value to preselect in the filter, applied once on first filter render then reset
39
+ defaultValue: null,//value to preselect in the insert row, applied every time a fresh insert row is built (not reset after use, unlike defaultSelected)
39
40
 
40
41
  itemTemplate: function (value) {
41
42
  var items = this.items,
@@ -64,7 +65,11 @@
64
65
  if (!this.inserting)
65
66
  return "";
66
67
 
67
- return this.insertControl = this._createSelect();
68
+ var $result = this.insertControl = this._createSelect();
69
+ if (this.defaultValue !== null) {
70
+ $result.val(this.defaultValue);
71
+ }
72
+ return $result;
68
73
  },
69
74
 
70
75
  editTemplate: function (value) {
@@ -20,6 +20,7 @@
20
20
  autosearch: true,
21
21
  readOnly: false,
22
22
  defaultSelected: null,//value to preset the filter input with, applied once on first filter render then reset
23
+ defaultValue: null,//value to prefill the insert row with, applied every time a fresh insert row is built (not reset after use, unlike defaultSelected)
23
24
 
24
25
  filterTemplate: function () {
25
26
  if (!this.filtering)
@@ -49,7 +50,11 @@
49
50
  if (!this.inserting)
50
51
  return "";
51
52
 
52
- return this.insertControl = this._createTextBox();
53
+ var $result = this.insertControl = this._createTextBox();
54
+ if (this.defaultValue !== null) {
55
+ $result.val(this.defaultValue);
56
+ }
57
+ return $result;
53
58
  },
54
59
 
55
60
  editTemplate: function (value) {
@@ -1,11 +1,11 @@
1
- (function(jsGrid, $, undefined) {
2
-
3
- if (!jsGrid) {
4
- if (window.console) {
5
- console.error("[jsxgrid] jsgrid.field.Xtextarea.js was loaded before the jsxgrid engine (jsxgrid.js) - include the engine first.");
6
- }
7
- return;
8
- }
1
+ (function(jsGrid, $, undefined) {
2
+
3
+ if (!jsGrid) {
4
+ if (window.console) {
5
+ console.error("[jsxgrid] jsgrid.field.Xtextarea.js was loaded before the jsxgrid engine (jsxgrid.js) - include the engine first.");
6
+ }
7
+ return;
8
+ }
9
9
 
10
10
 
11
11
  // Standalone: does not extend jsGrid.TextAreaField, only jsGrid.Field.
@@ -21,6 +21,7 @@
21
21
  readOnly: false,
22
22
  maxShowSymbols: 50,
23
23
  defaultSelected: null,//value to preset the filter input with, applied once on first filter render then reset
24
+ defaultValue: null,//value to prefill the insert row with, applied every time a fresh insert row is built (not reset after use, unlike defaultSelected)
24
25
 
25
26
  filterTemplate: function () {
26
27
  if (!this.filtering)
@@ -54,7 +55,11 @@
54
55
  if (!this.inserting)
55
56
  return "";
56
57
 
57
- return this.insertControl = this._createTextArea();
58
+ var $result = this.insertControl = this._createTextArea();
59
+ if (this.defaultValue !== null) {
60
+ $result.val(this.defaultValue);
61
+ }
62
+ return $result;
58
63
  },
59
64
 
60
65
  editTemplate: function (value) {
@@ -136,6 +136,13 @@
136
136
  sortAscClass: "jsgrid-header-sort jsgrid-header-sort-asc",
137
137
  sortDescClass: "jsgrid-header-sort jsgrid-header-sort-desc",
138
138
 
139
+ // jsxgrid extension: initial sort applied once at construction (field
140
+ // name/index/reference + "asc"/"desc"), baked into the first render/load
141
+ // instead of requiring a separate sort() call (and the extra
142
+ // refresh/reload that would trigger) right after creating the grid.
143
+ sortField: null,
144
+ sortOrder: null,
145
+
139
146
  paging: false,
140
147
  pagerContainer: null,
141
148
  pageIndex: 1,
@@ -209,11 +216,54 @@
209
216
  this._initLoadStrategy();
210
217
  this._initController();
211
218
  this._initFields();
219
+ this._initSorting();
212
220
  this._attachWindowLoadResize();
213
221
  this._attachWindowResizeCallback();
214
222
  this._callEventHandler(this.onInit)
215
223
  },
216
224
 
225
+ _initSorting: function() {
226
+ if(!this.sortField) {
227
+ return;
228
+ }
229
+
230
+ var field = this._normalizeField(this.sortField);
231
+ if(!field) {
232
+ return;
233
+ }
234
+
235
+ this._sortField = field;
236
+ this._sortOrder = this.sortOrder || SORT_ORDER_ASC;
237
+
238
+ // Static in-memory data (already present at construction time, not
239
+ // fetched via a controller) needs an explicit sort here - normal
240
+ // rendering never sorts on its own, only an actual sort() call does
241
+ // (see DirectLoadingStrategy.sort()).
242
+ if($.isArray(this.data) && this.data.length) {
243
+ this._sortData();
244
+ return;
245
+ }
246
+
247
+ // Controller-backed, non-paged grid: data isn't loaded yet at this
248
+ // point (arrives later via finishLoad), so there's nothing to sort
249
+ // here. Without this flag the header would still show the sort
250
+ // arrow (see _createHeaderRow()) while the actual rows stay in
251
+ // whatever order the controller returned - and the first real
252
+ // click on that same header would then look like it skips
253
+ // straight past the "ascending" pass, since _setSortingParams()
254
+ // reverses the order when clicking the field _sortField already
255
+ // points at. Picked up once, in _handleOptionChange's "data" case,
256
+ // as soon as the first load actually lands.
257
+ // pageLoading grids are excluded - sorting for those already
258
+ // happens server-side, from the sortField/sortOrder this same
259
+ // init sends along in the very first loadData() filter (see
260
+ // _sortingParams()); sorting the current page again client-side on
261
+ // top of that would be redundant at best.
262
+ if(!this.pageLoading) {
263
+ this._pendingInitialSort = true;
264
+ }
265
+ },
266
+
217
267
  _initInstanceLocale: function(locale) {
218
268
  if(!locale) {
219
269
  return;
@@ -382,6 +432,12 @@
382
432
  this.render();
383
433
  break;
384
434
  case "data":
435
+ if(this._pendingInitialSort) {
436
+ this._pendingInitialSort = false;
437
+ this._sortData();
438
+ }
439
+ this.refresh();
440
+ break;
385
441
  case "editing":
386
442
  case "heading":
387
443
  case "filtering":
@@ -533,6 +589,10 @@
533
589
  .on("click", $.proxy(function() {
534
590
  this.sort(index);
535
591
  }, this));
592
+
593
+ if(field === this._sortField) {
594
+ $th.addClass(this._sortOrder === SORT_ORDER_ASC ? this.sortAscClass : this.sortDescClass);
595
+ }
536
596
  }
537
597
  });
538
598