jquery.dataTables.rowGrouping.js
32.1 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
/*
* File: jquery.dataTables.grouping.js
* Version: 1.2.11.
* Author: Jovan Popovic
*
* https://github.com/djwoodward/jquery-datatables-row-grouping/blob/master/media/js/jquery.dataTables.rowGrouping.js
* Originally hosted at https://code.google.com/p/jquery-datatables-row-grouping
*
* Copyright 2013 Jovan Popovic, all rights reserved.
*
* This source file is free software, under either the GPL v2 license or a
* BSD style license, as supplied with this software.
*
* This source file is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE.
* Parameters:
* @iGroupingColumnIndex Integer Index of the column that will be used for grouping - default 0
* @sGroupingColumnSortDirection Enumeration Sort direction of the group
* @iGroupingOrderByColumnIndex Integer Index of the column that will be used for ordering groups
* @sGroupingClass String Class that will be associated to the group row. Default - "group"
* @sGroupItemClass String Class that will be associated to the group row of group items. Default - "group-item"
* @bSetGroupingClassOnTR Boolean If set class will be set to the TR instead of the TD withing the grouping TR
* @bHideGroupingColumn Boolean Hide column used for grouping once results are grouped. Default - true
* @bHideGroupingOrderByColumn Boolean Hide column used for ordering groups once results are grouped. Default - true
* @sGroupBy Enumeration Type of grouping that should be applied. Values "name"(default), "letter", "year"
* @sGroupLabelPrefix String Prefix that will be added to each group cell
* @bExpandableGrouping Boolean Attach expand/collapse handlers to the grouping rows
* @bExpandSingleGroup Boolean Use accordon grouping
* @iExpandGroupOffset Integer Number of pixels to set scroll position above the currently selected group. If -1 scroll will be alligned to the table
* General settings
* @sDateFormat: "dd/MM/yyyy" String Date format used for grouping
* @sEmptyGroupLabel String Lable that will be placed as group if grouping cells are empty. Default "-"
* Parameters used in the second level grouping
* @iGroupingColumnIndex2 Integer Index of the secondary column that will be used for grouping - default 0
* @sGroupingColumnSortDirection2 Enumeration Sort direction of the secondary group
* @iGroupingOrderByColumnIndex2 Integer Index of the column that will be used for ordering secondary groups
* @sGroupingClass2 String Class that will be associated to the secondary group row. Default "subgroup"
* @sGroupItemClass2 String Class that will be associated to the secondary group row of group items. Default "subgroup-item"
* @bHideGroupingColumn2 Boolean Hide column used for secondary grouping once results are grouped. Default - true,
* @bHideGroupingOrderByColumn2 Boolean Hide column used for ordering secondary groups once results are grouped. Default - true,
* @sGroupBy2 Enumeration Type of grouping that should be applied to secondary column. Values "name"(default), "letter", "year",
* @sGroupLabelPrefix2 String Prefix that will be added to each secondary group cell
* @fnOnGrouped Function Function that is called when grouping is finished. Function has no parameters.
*/
(function ($) {
"use strict";
$.fn.rowGrouping = function (options) {
function _fnOnGrouped() {
}
function _fnOnGroupCreated(oGroup, sGroup, iLevel) {
///<summary>
///Function called when a new grouping row is created(it should be overriden in properties)
///</summary>
}
function _fnOnGroupCompleted(oGroup, sGroup, iLevel) {
///<summary>
///Function called when a new grouping row is created(it should be overriden in properties)
///</summary>
}
function _getMonthName(iMonth) {
var asMonths = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
return asMonths[iMonth - 1];
}
var defaults = {
iGroupingColumnIndex: 0,
sGroupingColumnSortDirection: "",
iGroupingOrderByColumnIndex: -1,
sGroupingClass: "group",
sGroupItemClass: "group-item",
bHideGroupingColumn: true,
bHideGroupingOrderByColumn: true,
sGroupBy: "name",
sGroupLabelPrefix: "",
fnGroupLabelFormat: function (label) { return label; },
bExpandableGrouping: false,
bExpandSingleGroup: false,
iExpandGroupOffset: 100,
asExpandedGroups: null,
sDateFormat: "dd/MM/yyyy",
sEmptyGroupLabel: "-",
bSetGroupingClassOnTR: false,
iGroupingColumnIndex2: -1,
sGroupingColumnSortDirection2: "",
iGroupingOrderByColumnIndex2: -1,
sGroupingClass2: "subgroup",
sGroupItemClass2: "subgroup-item",
bHideGroupingColumn2: true,
bHideGroupingOrderByColumn2: true,
sGroupBy2: "name",
sGroupLabelPrefix2: "",
fnGroupLabelFormat2: function (label) { return label; },
bExpandableGrouping2: false,
fnOnGrouped: _fnOnGrouped,
fnOnGroupCreated: _fnOnGroupCreated,
fnOnGroupCompleted: _fnOnGroupCompleted,
oHideEffect: null, // { method: "hide", duration: "fast", easing: "linear" },
oShowEffect: null,//{ method: "show", duration: "slow", easing: "linear" }
bUseFilteringForGrouping: false // This is still work in progress option
};
return this.each(function (index, elem) {
var oTable = $(elem).dataTable();
var aoGroups = new Array();
$(this).dataTableExt.aoGroups = aoGroups;
function fnCreateGroupRow(sGroupCleaned, sGroup, iColspan) {
var nGroup = document.createElement('tr');
var nCell = document.createElement('td');
nGroup.id = "group-id-" + oTable.attr("id") + "_" + sGroupCleaned;
var oGroup = { id: nGroup.id, key: sGroupCleaned, text: sGroup, level: 0, groupItemClass: ".group-item-" + sGroupCleaned, dataGroup: sGroupCleaned, aoSubgroups: new Array() };
if (properties.bSetGroupingClassOnTR) {
nGroup.className = properties.sGroupingClass + " " + sGroupCleaned;
} else {
nCell.className = properties.sGroupingClass + " " + sGroupCleaned;
}
nCell.colSpan = iColspan;
nCell.innerHTML = properties.sGroupLabelPrefix + properties.fnGroupLabelFormat(sGroup == "" ? properties.sEmptyGroupLabel : sGroup, oGroup );
if (properties.bExpandableGrouping) {
if (!_fnIsGroupCollapsed(sGroupCleaned)) {
nCell.className += " expanded-group";
oGroup.state = "expanded";
} else {
nCell.className += " collapsed-group";
oGroup.state = "collapsed";
}
nCell.className += " group-item-expander";
$(nCell).attr('data-group', oGroup.dataGroup); //Fix provided by mssskhalsa (Issue 5)
$(nCell).attr("data-group-level", oGroup.level);
$(nCell).click(_fnOnGroupClick);
}
nGroup.appendChild(nCell);
aoGroups[sGroupCleaned] = oGroup;
oGroup.nGroup = nGroup;
properties.fnOnGroupCreated(oGroup, sGroupCleaned, 1);
return oGroup;
}
function _fnCreateGroup2Row(sGroup2, sGroupLabel, iColspan, oParentGroup) {
var nGroup2 = document.createElement('tr');
nGroup2.id = oParentGroup.id + "_" + sGroup2;
var nCell2 = document.createElement('td');
var dataGroup = oParentGroup.dataGroup + '_' + sGroup2;
var oGroup = { id: nGroup2.id, key: sGroup2, text: sGroupLabel, level: oParentGroup.level + 1, groupItemClass: ".group-item-" + dataGroup,
dataGroup: dataGroup, aoSubgroups: new Array()
};
if (properties.bSetGroupingClassOnTR) {
nGroup2.className = properties.sGroupingClass2 + " " + sGroup2;
} else {
nCell2.className = properties.sGroupingClass2 + " " + sGroup2;
}
nCell2.colSpan = iColspan;
nCell2.innerHTML = properties.sGroupLabelPrefix2 + properties.fnGroupLabelFormat2(sGroupLabel == "" ? properties.sEmptyGroupLabel : sGroupLabel, oGroup);
if (properties.bExpandableGrouping) {
nGroup2.className += " group-item-" + oParentGroup.dataGroup;
}
if (properties.bExpandableGrouping && properties.bExpandableGrouping2) {
if (!_fnIsGroupCollapsed(oGroup.dataGroup)) {
nCell2.className += " expanded-group";
oGroup.state = "expanded";
} else {
nCell2.className += " collapsed-group";
oGroup.state = "collapsed";
}
nCell2.className += " group-item-expander";
$(nCell2).attr('data-group', oGroup.dataGroup);
$(nCell2).attr("data-group-level", oGroup.level);
$(nCell2).click(_fnOnGroupClick);
}
nGroup2.appendChild(nCell2);
oParentGroup.aoSubgroups[oGroup.dataGroup] = oGroup;
aoGroups[oGroup.dataGroup] = oGroup;
oGroup.nGroup = nGroup2;
properties.fnOnGroupCreated(oGroup, sGroup2, 2);
return oGroup;
}
function _fnIsGroupCollapsed(sGroup) {
if (aoGroups[sGroup] != null)
return (aoGroups[sGroup].state == "collapsed");
else
if (sGroup.indexOf("_") > -1)
true;
else
if(bInitialGrouping && (asExpandedGroups==null || asExpandedGroups.length == 0))
return false;// initially if asExpandedGroups is empty - no one is collapsed
else
return ($.inArray(sGroup, asExpandedGroups) == -1); //the last chance check asExpandedGroups
}
function _fnGetYear(x) {
if(x.length< (iYearIndex+iYearLength) )
return x;
else
return x.substr(iYearIndex, iYearLength);
}
function _fnGetGroupByName(x) {
return x;
}
function _fnGetGroupByLetter(x) {
return x.substr(0, 1);
}
function _fnGetGroupByYear(x) {
return _fnGetYear(x);
//return Date.parseExact(x, properties.sDateFormat).getFullYear();//slooooow
}
function _fnGetGroupByYearMonth(x) {
//var date = Date.parseExact(x, "dd/MM/yyyy");
//return date.getFullYear() + " / " + date.getMonthName();
//return x.substr(iYearIndex, iYearLength) + '/' + x.substr(iMonthIndex, iMonthLength);
return x.substr(iYearIndex, iYearLength) + ' ' + _getMonthName(x.substr(iMonthIndex, iMonthLength));
}
function _fnGetCleanedGroup(sGroup) {
if (typeof sGroup === "undefined" || sGroup === "") return properties.sEmptyGroupLabel;
return sGroup.toLowerCase().replace(/[^a-zA-Z0-9\u0080-\uFFFF]+/g, "-"); //fix for unicode characters (Issue 23)
//return sGroup.toLowerCase().replace(/\W+/g, "-"); //Fix provided by bmathews (Issue 7)
}
function _rowGroupingRowFilter(oSettings, aData, iDataIndex) {
///<summary>Used to expand/collapse groups with DataTables filtering</summary>
if (oSettings.nTable.id !== oTable[0].id) return true;
var sColData = aData[properties.iGroupingColumnIndex];
if (typeof sColData === "undefined")
sColData = aData[oSettings.aoColumns[properties.iGroupingColumnIndex].mData];
if (_fnIsGroupCollapsed(_fnGetCleanedGroup(sColData))) {
if (oTable.fnIsOpen(oTable.fnGetNodes(iDataIndex)))
{
if (properties.fnOnRowClosed != null) {
properties.fnOnRowClosed(this); // $(this.cells[0].children[0]).attr('src', '../../Images/details.png');
}
oTable.fnClose(oTable.fnGetNodes(iDataIndex));
}
return false;
};
return true;
} //end of function _rowGroupingRowFilter
function fnExpandGroup(sGroup) {
///<summary>Expand group if expanadable grouping is used</summary>
aoGroups[sGroup].state = "expanded";
$("td[data-group='" + sGroup + "']").removeClass("collapsed-group");
$("td[data-group='" + sGroup + "']").addClass("expanded-group");
if(properties.bUseFilteringForGrouping)
{
oTable.fnDraw();
return;//Because rows are expanded with _rowGroupingRowFilter function
}
if (jQuery.inArray(sGroup, asExpandedGroups)==-1)
asExpandedGroups.push(sGroup);
if (properties.oHideEffect != null)
$(".group-item-" + sGroup, oTable)
[properties.oShowEffect.method](properties.oShowEffect.duration,
properties.oShowEffect.easing,
function () { });
else
$(".group-item-" + sGroup, oTable).show();
} //end of function fnExpandGroup
function fnCollapseGroup(sGroup) {
///<summary>Collapse group if expanadable grouping is used</summary>
aoGroups[sGroup].state = "collapsed";
$("td[data-group='" + sGroup + "']").removeClass("expanded-group");
$("td[data-group='" + sGroup + "']").addClass("collapsed-group");
if(properties.bUseFilteringForGrouping)
{
oTable.fnDraw();
return;//Because rows are expanded with _rowGroupingRowFilter function
}
//var index = $.inArray(sGroup, asExpandedGroups);
//asExpandedGroups.splice(index, 1);
$('.group-item-' + sGroup).each(function () {
//Issue 24 - Patch provided by Bob Graham
if (oTable.fnIsOpen(this)) {
if (properties.fnOnRowClosed != null) {
properties.fnOnRowClosed(this); // $(this.cells[0].children[0]).attr('src', '../../Images/details.png');
}
oTable.fnClose(this);
}
});
if (properties.oHideEffect != null)
$(".group-item-" + sGroup, oTable)
[properties.oHideEffect.method](properties.oHideEffect.duration,
properties.oHideEffect.easing,
function () { });
else
$(".group-item-" + sGroup, oTable).hide();
} //end of function fnCollapseGroup
function _fnOnGroupClick(e) {
///<summary>
///Function that is called when user click on the group cell in order to
///expand of collapse group
///</summary>
//var sGroup = $(this).attr("rel");
var sGroup = $(this).attr("data-group");
var iGroupLevel = $(this).attr("data-group-level");
var bIsExpanded = !_fnIsGroupCollapsed(sGroup);
if (properties.bExpandSingleGroup) {
if (!bIsExpanded) {
var sCurrentGroup = $("td.expanded-group").attr("data-group");
fnCollapseGroup(sCurrentGroup);
fnExpandGroup(sGroup);
if (properties.iExpandGroupOffset != -1) {
var position = $("#group-id-" + oTable.attr("id") + "_" + sGroup).offset().top - properties.iExpandGroupOffset;
window.scroll(0, position);
} else {
var position = oTable.offset().top;
window.scroll(0, position);
}
}
} else {
if (bIsExpanded) {
fnCollapseGroup(sGroup);
} else {
fnExpandGroup(sGroup);
}
}
e.preventDefault();
}; //end function _fnOnGroupClick
function _fnDrawCallBackWithGrouping (oSettings) {
if (oTable.fnSettings().oFeatures.bServerSide)
bInitialGrouping = true;
var bUseSecondaryGrouping = false;
if (properties.iGroupingColumnIndex2 != -1)
bUseSecondaryGrouping = true;
//-----Start grouping
if (oSettings.aiDisplayMaster.length == 0) { //aiDisplay
return;
}
var nTrs = $('tbody tr', oTable);
var iColspan = 0; //nTrs[0].getElementsByTagName('td').length;
for (var iColIndex = 0; iColIndex < oSettings.aoColumns.length; iColIndex++) {
if (oSettings.aoColumns[iColIndex].bVisible)
iColspan += 1;
}
var sLastGroup = null;
var sLastGroup2 = null;
if (oSettings.aiDisplay.length > 0) {
for (var i = 0; i < nTrs.length; i++) {
var iDisplayIndex = oSettings._iDisplayStart + i;
if (oTable.fnSettings().oFeatures.bServerSide)
iDisplayIndex = i;
var sGroupData = "";
var sGroup = null;
var sGroupData2 = "";
var sGroup2 = null;
//Issue 31 - Start fix provided by Fabien Taysse
// sGroupData = oSettings.aoData[oSettings.aiDisplay[iDisplayIndex]]._aData[properties.iGroupingColumnIndex];
// if (sGroupData == undefined)
// sGroupData = oSettings.aoData[oSettings.aiDisplay[iDisplayIndex]]._aData[oSettings.aoColumns[properties.iGroupingColumnIndex].mData];
sGroupData = this.fnGetData(nTrs[i], properties.iGroupingColumnIndex);
//Issue 31 - End fix provided by Fabien Taysse
var sGroup = sGroupData;
if (properties.sGroupBy != "year")
sGroup = fnGetGroup(sGroupData);
if (bUseSecondaryGrouping) {
sGroupData2 = oSettings.aoData[oSettings.aiDisplay[iDisplayIndex]]._aData[properties.iGroupingColumnIndex2];
if (sGroupData2 == undefined)
sGroupData2 = oSettings.aoData[oSettings.aiDisplay[iDisplayIndex]]._aData[oSettings.aoColumns[properties.iGroupingColumnIndex2].mData];
if (properties.sGroupBy2 != "year")
sGroup2 = fnGetGroup(sGroupData2);
}
if (sLastGroup == null || _fnGetCleanedGroup(sGroup) != _fnGetCleanedGroup(sLastGroup)) { // new group encountered (or first of group)
var sGroupCleaned = _fnGetCleanedGroup(sGroup);
if(sLastGroup != null)
{
properties.fnOnGroupCompleted(aoGroups[_fnGetCleanedGroup(sLastGroup)]);
}
/*
if (properties.bExpandableGrouping && bInitialGrouping) {
if (properties.bExpandSingleGroup) {
if (asExpandedGroups.length == 0)
asExpandedGroups.push(sGroupCleaned);
} else {
asExpandedGroups.push(sGroupCleaned);
}
}
*/
if(properties.bAddAllGroupsAsExpanded && jQuery.inArray(sGroupCleaned,asExpandedGroups) == -1)
asExpandedGroups.push(sGroupCleaned);
var oGroup = fnCreateGroupRow(sGroupCleaned, sGroup, iColspan);
var nGroup = oGroup.nGroup;
if(nTrs[i].parentNode!=null)
nTrs[i].parentNode.insertBefore(nGroup, nTrs[i]);
else
$(nTrs[i]).before(nGroup);
sLastGroup = sGroup;
sLastGroup2 = null; //to reset second level grouping
} // end if (sLastGroup == null || sGroup != sLastGroup)
$(nTrs[i]).attr("data-group", aoGroups[sGroupCleaned].dataGroup);
$(nTrs[i]).addClass(properties.sGroupItemClass);
$(nTrs[i]).addClass("group-item-" + sGroupCleaned);
if (properties.bExpandableGrouping) {
if (_fnIsGroupCollapsed(sGroupCleaned) && !properties.bUseFilteringForGrouping) {
$(nTrs[i]).hide();
}
}
if (bUseSecondaryGrouping) {
if (sLastGroup2 == null || _fnGetCleanedGroup(sGroup2) != _fnGetCleanedGroup(sLastGroup2)) {
var sGroup2Id = _fnGetCleanedGroup(sGroup) + '-' + _fnGetCleanedGroup(sGroup2);
var oGroup2 = _fnCreateGroup2Row(sGroup2Id, sGroup2, iColspan, aoGroups[sGroupCleaned])
var nGroup2 = oGroup2.nGroup;
nTrs[i].parentNode.insertBefore(nGroup2, nTrs[i]);
sLastGroup2 = sGroup2;
}
$(nTrs[i]).attr("data-group", oGroup2.dataGroup)
.addClass(properties.sGroupItemClass2)
.addClass("group-item-" + oGroup2.dataGroup);
} //end if (bUseSecondaryGrouping)
} // end for (var i = 0; i < nTrs.length; i++)
}; // if (oSettings.aiDisplay.length > 0)
if(sLastGroup != null)
{
properties.fnOnGroupCompleted(aoGroups[_fnGetCleanedGroup(sLastGroup)]);
}
//-----End grouping
properties.fnOnGrouped(aoGroups);
bInitialGrouping = false;
}; // end of _fnDrawCallBackWithGrouping = function (oSettings)
//var oTable = this;
var iYearIndex = 6;
var iYearLength = 4;
var asExpandedGroups = new Array();
var bInitialGrouping = true;
var properties = $.extend(defaults, options);
if (properties.iGroupingOrderByColumnIndex == -1) {
properties.bCustomColumnOrdering = false;
properties.iGroupingOrderByColumnIndex = properties.iGroupingColumnIndex;
} else {
properties.bCustomColumnOrdering = true;
}
if (properties.sGroupingColumnSortDirection == "") {
if (properties.sGroupBy == "year")
properties.sGroupingColumnSortDirection = "desc";
else
properties.sGroupingColumnSortDirection = "asc";
}
if (properties.iGroupingOrderByColumnIndex2 == -1) {
properties.bCustomColumnOrdering2 = false;
properties.iGroupingOrderByColumnIndex2 = properties.iGroupingColumnIndex2;
} else {
properties.bCustomColumnOrdering2 = true;
}
if (properties.sGroupingColumnSortDirection2 == "") {
if (properties.sGroupBy2 == "year")
properties.sGroupingColumnSortDirection2 = "desc";
else
properties.sGroupingColumnSortDirection2 = "asc";
}
iYearIndex = properties.sDateFormat.toLowerCase().indexOf('yy');
iYearLength = properties.sDateFormat.toLowerCase().lastIndexOf('y') - properties.sDateFormat.toLowerCase().indexOf('y') + 1;
var iMonthIndex = properties.sDateFormat.toLowerCase().indexOf('mm');
var iMonthLength = properties.sDateFormat.toLowerCase().lastIndexOf('m') - properties.sDateFormat.toLowerCase().indexOf('m') + 1;
var fnGetGroup = _fnGetGroupByName;
switch (properties.sGroupBy) {
case "letter": fnGetGroup = _fnGetGroupByLetter;
break;
case "year": fnGetGroup = _fnGetGroupByYear;
break;
case "month": fnGetGroup = _fnGetGroupByYearMonth;
break;
default: fnGetGroup = _fnGetGroupByName;
break;
}
if (properties.asExpandedGroups != null) {
if (properties.asExpandedGroups == "NONE") {
properties.asExpandedGroups = [];
asExpandedGroups = properties.asExpandedGroups;
bInitialGrouping = false;
} else if (properties.asExpandedGroups == "ALL") {
properties.bAddAllGroupsAsExpanded = true;
} else if (properties.asExpandedGroups.constructor == String) {
var currentGroup = properties.asExpandedGroups;
properties.asExpandedGroups = new Array();
properties.asExpandedGroups.push(_fnGetCleanedGroup(currentGroup));
asExpandedGroups = properties.asExpandedGroups;
bInitialGrouping = false;
} else if (properties.asExpandedGroups.constructor == Array) {
for (var i = 0; i < properties.asExpandedGroups.length; i++) {
asExpandedGroups.push(_fnGetCleanedGroup(properties.asExpandedGroups[i]));
if (properties.bExpandSingleGroup)
break;
}
bInitialGrouping = false;
}
}else{
properties.asExpandedGroups = new Array();
properties.bAddAllGroupsAsExpanded = true;
}
if(properties.bExpandSingleGroup){
var nTrs = $('tbody tr', oTable);
var sGroupData = oTable.fnGetData(nTrs[0], properties.iGroupingColumnIndex);
var sGroup = sGroupData;
if (properties.sGroupBy != "year")
sGroup = fnGetGroup(sGroupData);
var sGroupCleaned = _fnGetCleanedGroup(sGroup);
properties.asExpandedGroups = new Array();
properties.asExpandedGroups.push(sGroupCleaned);
}
oTable.fnSetColumnVis(properties.iGroupingColumnIndex, !properties.bHideGroupingColumn);
if (properties.bCustomColumnOrdering) {
oTable.fnSetColumnVis(properties.iGroupingOrderByColumnIndex, !properties.bHideGroupingOrderByColumn);
}
if (properties.iGroupingColumnIndex2 != -1) {
oTable.fnSetColumnVis(properties.iGroupingColumnIndex2, !properties.bHideGroupingColumn2);
}
if (properties.bCustomColumnOrdering2) {
oTable.fnSetColumnVis(properties.iGroupingOrderByColumnIndex2, !properties.bHideGroupingOrderByColumn2);
}
oTable.fnSettings().aoDrawCallback.push({
"fn": _fnDrawCallBackWithGrouping,
"sName": "fnRowGrouping"
});
var aaSortingFixed = new Array();
aaSortingFixed.push([properties.iGroupingOrderByColumnIndex, properties.sGroupingColumnSortDirection]);
if (properties.iGroupingColumnIndex2 != -1) {
aaSortingFixed.push([properties.iGroupingOrderByColumnIndex2, properties.sGroupingColumnSortDirection2]);
} // end of if (properties.iGroupingColumnIndex2 != -1)
oTable.fnSettings().aaSortingFixed = aaSortingFixed;
//Old way
//oTable.fnSettings().aaSortingFixed = [[properties.iGroupingOrderByColumnIndex, properties.sGroupingColumnSortDirection]];
switch (properties.sGroupBy) {
case "name":
break;
case "letter":
/* Create an array with the values of all the input boxes in a column */
oTable.fnSettings().aoColumns[properties.iGroupingOrderByColumnIndex].sSortDataType = "rg-letter";
$.fn.dataTableExt.afnSortData['rg-letter'] = function (oSettings, iColumn) {
var aData = [];
$('td:eq(' + iColumn + ')', oSettings.oApi._fnGetTrNodes(oSettings)).each(function () {
aData.push(_fnGetGroupByLetter(this.innerHTML));
});
return aData;
}
break;
case "year":
/* Create an array with the values of all the input boxes in a column */
oTable.fnSettings().aoColumns[properties.iGroupingOrderByColumnIndex].sSortDataType = "rg-date";
$.fn.dataTableExt.afnSortData['rg-date'] = function (oSettings, iColumn) {
var aData = [];
var nTrs = oSettings.oApi._fnGetTrNodes(oSettings);
for(i = 0; i< nTrs.length; i++)
{
aData.push(_fnGetYear( oTable.fnGetData( nTrs[i], iColumn) ));
}
/*
$('td:eq(' + iColumn + ')', oSettings.oApi._fnGetTrNodes(oSettings)).each(function () {
aData.push(_fnGetYear(this.innerHTML));
});
*/
return aData;
}
break;
default:
break;
} // end of switch (properties.sGroupBy)
if(properties.bUseFilteringForGrouping)
$.fn.dataTableExt.afnFiltering.push(_rowGroupingRowFilter);
oTable.fnDraw();
});
};
})(jQuery);