-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTable.js
More file actions
1463 lines (1198 loc) · 45.2 KB
/
Table.js
File metadata and controls
1463 lines (1198 loc) · 45.2 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
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
if(!javaxt) var javaxt={};
if(!javaxt.dhtml) javaxt.dhtml={};
//******************************************************************************
//** Table Class
//******************************************************************************
/**
* Scrollable table with a fixed header.
*
******************************************************************************/
javaxt.dhtml.Table = function(parent, config) {
this.className = "javaxt.dhtml.Table";
var me = this;
var deferUpdate = false;
var header, body; //tbody elements
var bodyDiv; //overflow div
var mask;
var prevSelection;
var template;
var cntrlIsPressed = false;
var shiftIsPressed = false;
var altIsPressed = false;
var scrollEnabled = true;
var defaultConfig = {
/** Column definitions for the table. This config is required. Example:
<pre>
columns: [
{header: 'ID', hidden:true},
{header: 'Name', width:'100%'},
{header: 'Username', width:'150'},
{header: 'Role', width:'100'},
{header: 'Enabled', width:'80', align:'center'},
{header: 'Last Active', width:'150', align:'right'}
]
</pre>
Column headers are used as labels in the header row. They are also
used as column identifiers using the get and set methods for a row.
<p/>
Column widths can be defined using percentages (e.g. '100%') or in
pixels (e.g. '100px' or '100' or 100). Normally, there should be one
column with a width of '100%'. This will allow the column fill all
available area not occupied by columns with fixed column widths. The
only exception is to define multiple columns with percentages as long
as all the percentages add up to 100%.
<p/>
Column alignment is used to set the alignment of the cells associated
with the column. Options include 'left', 'right', and 'center'.
*/
columns: [],
/** If true, the table will allow users to select multiple rows using
* control or shift key. Default is false (only one row is selected at
* a time).
*/
multiselect: false,
/** If true, the table will render a vertical scrollbar, allowing users
* to scroll up/down and see rows that are out of view. If false, the
* scrollbar is hidden from view. Default is true.
*/
overflow: true,
/** If true, will hide the header row. Default is false.
*/
hideHeader: false,
/** If true, will set browser focus on the table when the mouse is
* detected over the table. Default is false.
*/
focusOnMouseover: false,
/** Style for individual elements within the component. Note that you can
* provide CSS class names instead of individual style definitions.
*/
style: {
table: {
width: "100%",
height: "100%",
margin: 0,
padding: 0,
borderCollapse: "collapse"
},
headerRow: {
height: "35px",
borderBottom: "1px solid #8f8f8f",
background: "#eaeaea"
},
headerColumn: {
lineHeight: "35px",
borderLeft: "1px solid #cccccc",
borderRight: "1px solid #cccccc",
padding: "0 5px",
color: "#272727",
cursor: "pointer",
whiteSpace: "nowrap"
},
row: {
height: "35px",
borderBottom: "1px solid #cccccc"
},
column: {
height: "35px",
lineHeight: "35px",
borderLeft: "1px solid #cccccc",
borderRight: "1px solid #cccccc",
padding: "0 5px",
color: "#272727",
cursor: "default",
whiteSpace: "nowrap"
},
selectedRow: {
height: "35px",
borderBottom: "1px solid #cccccc",
backgroundColor: "#FFFFB1"
},
resizeHandle: {
width: "5px",
cursor: "col-resize",
marginRight: "-2px"
},
mask: {
backgroundColor: "rgba(0,0,0,0.5)"
},
/** Style for iScroll (if present). If the style is set to null or
* false, uses inline style. If a "custom" keyword is given, will
* use "iScrollHorizontalScrollbar", "iScrollVerticalScrollbar",
* and "iScrollIndicator" classes defined in your css. You can also
* define custom class names by providing a style map like this:
<pre>
iscroll: {
horizontalScrollbar: "my-iScrollHorizontalScrollbar",
verticalScrollbar: "my-iScrollVerticalScrollbar",
indicator: "my-iScrollIndicator",
columnWidth: "15px"
}
</pre>
*/
iscroll: null
}
};
//**************************************************************************
//** Constructor
//**************************************************************************
/** Creates a new instance of this class. */
var init = function(){
if (typeof parent === "string"){
parent = document.getElementById(parent);
}
if (!parent) return;
//Clone the config so we don't modify the original config object
var clone = {};
merge(clone, config);
//Merge clone with default config
merge(clone, defaultConfig);
config = clone;
//Parse config
if (!config.columns || config.columns.length===0) return;
if (typeof IScroll !== 'undefined'){
var columnWidth = config.style.iscroll ? config.style.iscroll.columnWidth : null;
if (!columnWidth) columnWidth = "15px";
if (columnWidth<=0 || columnWidth==="0px" || columnWidth==="0%"){
//Allow users to not have a spacer for iScroll
}
else{
config.columns.push({header: '', width: columnWidth});
}
}
//Create main table
var table, tr, td;
table = createTable(parent);
table.className = "javaxt-table";
setStyle(table, "table");
me.el = table;
addShowHide(me);
addMask(parent);
//Create header
tr = table.addRow();
tr.setAttribute("desc", "Header Row");
setStyle(tr, "headerRow");
td = tr.addColumn();
td.style.width = "100%";
td.style.height = "inherit";
header = createTable(td);
if (config.hideHeader===true){
tr.style.visibility = 'hidden';
tr.style.display = 'none';
}
//Create body
tr = table.addRow();
tr.setAttribute("desc", "Body Row");
td = tr.addColumn({
width: "100%",
height: "100%"
});
bodyDiv = createElement('div', td, {
width: "100%",
height: "100%",
position: "relative"
});
bodyDiv.setAttribute("desc", "body-div");
bodyDiv.tabIndex = -1; //allows the div to have focus
bodyDiv.onmouseover = function(){
if (config.focusOnMouseover===true){
var x = window.scrollX, y = window.scrollY;
this.focus();
window.scrollTo(x, y);
}
};
bodyDiv.addEventListener("keydown", function(e){
if (e.keyCode===16){
shiftIsPressed = true;
}
if (e.keyCode===17){
cntrlIsPressed = true;
}
if (e.keyCode===18){
altIsPressed = true;
}
//Prevent window from scrolling
if (e.keyCode===38 || e.keyCode===40){
e.preventDefault();
e.stopPropagation();
}
});
bodyDiv.addEventListener("keyup", function(e){
if (e.keyCode===16){
shiftIsPressed = false;
}
if (e.keyCode===17){
cntrlIsPressed = false;
}
if (e.keyCode===18){
altIsPressed = false;
}
if (e.keyCode===38 || e.keyCode===40){
var lastSelectedRow, lastRow;
me.forEachRow(function (row) {
if (row.selected){
lastSelectedRow = row;
}
lastRow = row;
});
if (lastSelectedRow){
var row;
if (e.keyCode===40){ //down arrow
row = lastSelectedRow.nextSibling;
}
else{ //up arrow
row = lastSelectedRow.previousSibling;
}
if (row){
me.scrollTo(row);
row.click();
}
}
}
me.onKeyEvent(e.keyCode, {
shift: shiftIsPressed,
ctrl: cntrlIsPressed,
alt: altIsPressed
});
});
bodyDiv = createElement('div', bodyDiv, {
width: "100%",
height: "100%",
position: "absolute",
overflow: "scroll",
overflowX: "hidden"
});
body = createTable(bodyDiv);
body.style.height = '';
//Populate header
tr = createPhantomRow(header, 1);
var spacerUR = createElement('div', tr.addColumn());
tr = header.addRow();
for (var i=0; i<config.columns.length; i++){
var columnConfig = config.columns[i];
//Update right aligned columns to have center align headers
var align = columnConfig.align;
if (align=="right") columnConfig.align = "center";
//Create cell
var cell = createCell(columnConfig, true, i);
//Reset alignment in the config
columnConfig.align = align;
//Set content
cell.setContent(columnConfig.header);
//Create label/alias (see setRowContent)
if (typeof columnConfig.header === "string"){
columnConfig.label = columnConfig.header;
}
else{
columnConfig.label = columnConfig.header.innerText;
}
//OnClick events
cell.colID = i;
cell.onclick = function(event){
var colID = this.colID;
var colConfig = config.columns[colID];
me.onHeaderClick(colID,colConfig,this,event);
if (colConfig!=null){
var callback = colConfig.onHeaderClick;
if (callback!=null){
callback.apply(me, [i,cell,event]);
}
}
};
tr.appendChild(cell);
}
tr.addColumn(); //<-- add cell under the spacer
//Populate body
createPhantomRow(body, 1);
//Function called after the table has been added to the DOM
onRender(bodyDiv, function(){
var onScroll = function(scrollTop){
var maxScrollPosition = bodyDiv.scrollHeight - bodyDiv.clientHeight;
me.onScroll(scrollTop, maxScrollPosition, bodyDiv.offsetHeight);
};
//Configure iScroll as needed and watch for scroll events
if (typeof IScroll !== 'undefined'){
bodyDiv.style.overflowY = 'hidden';
me.iScroll = new IScroll(bodyDiv, {
scrollbars: config.style.iscroll ? "custom" : true,
mouseWheel: true, //enable scrolling with mouse wheel
fadeScrollbars: false,
hideScrollbars: false
});
if (config.style.iscroll) setStyle(me.iScroll, "iscroll");
//Override the iscroll's translate method so we can catch all
//scroll movements and prevent scrolling as needed
var translate = me.iScroll._translate;
me.iScroll._translate = function(x, y){
if (!scrollEnabled) return;
translate.apply(me.iScroll, arguments);
onScroll(-me.iScroll.y);
};
me.iScroll.on('beforeScrollStart', function(){
onScroll(-me.iScroll.y);
});
me.iScroll.on('scrollStart', function(){
onScroll(-me.iScroll.y);
});
me.iScroll.on('scrollEnd', function(){
onScroll(-me.iScroll.y);
});
}
else{
if (config.overflow===false) bodyDiv.style.overflowY = 'hidden';
bodyDiv.onscroll = function(e){
if (!scrollEnabled){ //not tested...
e.preventDefault();
return;
}
onScroll(bodyDiv.scrollTop);
};
}
//Update the spacer in the right column of the header
var bodyWidth = bodyDiv.offsetWidth;
var tableWidth = body.offsetWidth;
var scrollWidth = Math.abs(bodyWidth-tableWidth);
spacerUR.style.width = scrollWidth + "px";
//Watch for resize events
addResizeListener(parent, function(){
mask.resize();
me.update();
});
});
};
//**************************************************************************
//** createPhantomRow
//**************************************************************************
/** Insert phantom row into a given table. This helps the browser calculate
* column widths when columns are defined using percentages
*/
var createPhantomRow = function(table, height){
var row = table.addRow();
for (var i=0; i<config.columns.length; i++){
var columnConfig = config.columns[i];
var clonedColumnConfig = {};
merge(clonedColumnConfig, columnConfig);
var cell = row.addColumn();
cell.style.height = getPixels(height);
if (columnConfig.hidden === true){
cell.style.visibility = 'hidden';
cell.style.display = 'none';
cell.style.width = '0px';
}
else{
var columnWidth = columnConfig.width;
cell.style.width = getPixels((columnWidth==null) ? 25 : columnWidth);
var minWidth = columnConfig.minWidth;
if (minWidth) cell.style.minWidth = getPixels(minWidth);
}
var x = createElement("div", cell);
x.style.width = getPixels(((columnWidth+"").indexOf("%")>-1) ? 25 : columnWidth);
x.style.height = getPixels(height);
}
return row;
};
//**************************************************************************
//** createCell
//**************************************************************************
var createCell = function(columnConfig, isHeader, idx){
var cell = createElement('td');
if (isHeader===true){
setStyle(cell, "headerColumn");
}
else{
setStyle(cell, "column");
}
cell.style.textAlign = columnConfig.align;
//Hide column as needed
if (columnConfig.hidden === true){
cell.style.visibility = 'hidden';
cell.style.display = 'none';
}
//Make column text unselectable
if (columnConfig.selecttext === true){}
else{
cell.style.userSelect = "none";
cell.style.webkitUserSelect = "none";
cell.style.MozUserSelect = "none";
cell.setAttribute("unselectable", "on"); // For IE and Opera
}
//Create overflow divs
var outerDiv = createElement("div", cell, {
position: "relative",
height: "100%"
});
var innerDiv = createElement("div", outerDiv, {
position: "absolute",
width: "100%",
height: "100%",
overflow: "hidden"
});
//Add resize handle
if (columnConfig.resizable===true){
if (isHeader && idx<config.columns.length-1){
var handle = createElement("div", outerDiv);
setStyle(handle, "resizeHandle");
handle.style.position = "absolute";
handle.style.right = 0;
handle.style.top = 0;
handle.style.height = "100%";
}
}
//Set custom properties on the cell. Note that these
//properties will be lost if the cell is cloned.
cell.innerDiv = innerDiv;
cell.setContent = setContent;
cell.getContent = getContent;
return cell;
};
//**************************************************************************
//** addRows
//**************************************************************************
/** Appends multiple rows to the table. On some browsers (e.g. iPad) this
* method is significantly faster than calling addRow() multiple times.
* Example:
<pre>
table.addRows([
["Bob","12/30","$5.25"],
["Jim","10/28","$7.33"]
]);
</pre>
*/
this.addRows = function(rows){
//Check if rows is a number
if (!isArray(rows)){
rows = parseInt(rows);
if (isNaN(rows)) return;
else{
var numRows = rows;
rows = [];
var data = [];
for (var i=0; i<config.columns.length; i++){
data.push("");
}
for (var i=0; i<numRows; i++){
rows.push(data);
}
}
}
deferUpdate = true;
var arr = [];
for (var i=0; i<rows.length; i++){
arr.push(me.addRow(rows[i]));
}
deferUpdate = false;
me.update();
return arr;
};
//**************************************************************************
//** addRow
//**************************************************************************
/** Appends a row to the table and populates the cells with given values.
* Example:
<pre>
table.addRow("Bob","12/30","$5.25");
</pre>
* Note that this method also accepts an array of values. Example:
<pre>
table.addRow(["Bob","12/30","$5.25"]);
</pre>
*/
this.addRow = function(){
var data = arguments;
//Check if the first argument is an array. If so, use it.
//Otherwise, we'll use all the arguments as data.
if (isArray(data[0])) data = data[0];
//Create row
var row = body.addRow();
row.selected = false;
setStyle(row, "row");
//Add custom functions to the row
row.get = getRowContent;
row.set = setRowContent;
row.onclick = selectRows;
row.oncontextmenu = function(e){
if (this.selected) this.selected = false;
selectRows.apply(this, [e]);
};
//Create template as needed. The template is a collection of cells that
//are cloned whenever a new row is added. This approach results in faster
//row rendering.
if (!template){
template = [];
for (var i=0; i<config.columns.length; i++){
var columnConfig = config.columns[i];
var clonedColumnConfig = {};
merge(clonedColumnConfig, columnConfig);
var cell = createCell(clonedColumnConfig);
template.push(cell);
}
}
//Insert cells
for (var i=0; i<config.columns.length; i++){
var cell = template[i].cloneNode(true);
cell.innerDiv = cell.firstChild.firstChild;
cell.setContent = setContent;
cell.getContent = getContent;
cell.setContent(data[i]);
row.appendChild(cell);
}
//Update table as needed
if (!deferUpdate) me.update();
return row;
};
//**************************************************************************
//** setContent
//**************************************************************************
/** Used to set the content of a cell.
*/
var setContent = function(content){
if (content==null || typeof content === "undefined"){
this.innerDiv.innerHTML = "";
}
else{
if (isElement(content)){
this.innerDiv.innerHTML = "";
try{
this.innerDiv.appendChild(content);
return;
}
catch(e){
}
}
this.innerDiv.innerHTML = content;
}
};
//**************************************************************************
//** getContent
//**************************************************************************
/** Returns the content of a cell.
*/
var getContent = function(){
if (this.innerDiv.childNodes){
if (this.innerDiv.childNodes.length>0){
var content = this.innerDiv.childNodes[0];
if (content.nodeType===1) return content;
else return this.innerDiv.innerHTML;
}
}
return null;
};
//**************************************************************************
//** getRowContent
//**************************************************************************
/** Returns the content of a cell using a column name or index.
*/
var getRowContent = function(key){
var id = parseInt(key);
if (isNaN(id)){
for (var i=0; i<config.columns.length; i++){
var columnConfig = config.columns[i];
var label = columnConfig.label;
if (label===key){
return this.childNodes[i].getContent();
}
}
}
else{
return this.childNodes[id].getContent();
}
};
//**************************************************************************
//** setRowContent
//**************************************************************************
/** Used to set the content of a cell using a column name or index.
*/
var setRowContent = function(key, val){
var id = parseInt(key);
if (isNaN(id)){
for (var i=0; i<config.columns.length; i++){
var columnConfig = config.columns[i];
var label = columnConfig.label;
if (label===key){
this.childNodes[i].setContent(val);
return;
}
}
}
else{
if (id<0 || id>config.columns.length-1) return;
this.childNodes[id].setContent(val);
}
};
//**************************************************************************
//** selectRows
//**************************************************************************
/** Private method used to select rows in the grid.
*/
var selectRows = function(event){
var row = this;
var rows = [row];
var selectRow = function(){
var childNodes = body.getRows();
for (var i=1; i<childNodes.length; i++){
var tr = childNodes[i];
if (tr.selected){
me.deselect(tr);
rows.push(tr);
}
}
me.select(row);
};
//config.multiselect = false;
if (config.multiselect === true){
var e;
if (event) e = event;
else{ if (window.event) e = window.event; }
if (row.selected){
if (e.ctrlKey){
me.deselect(row);
var childNodes = body.getRows();
for (var i=1; i<childNodes.length; i++){
var tr = childNodes[i];
if (tr.selected && tr!=row){
rows.push(tr);
}
}
}
else{
var selectedRows = 0;
var childNodes = body.getRows();
for (var i=1; i<childNodes.length; i++){
var tr = childNodes[i];
if (tr.selected){
if (tr!=row) {
me.deselect(tr);
rows.push(tr);
selectedRows++;
}
}
}
if (selectedRows===0) me.deselect(row);
}
}
else{
if (e.shiftKey){
var tbody = row.parentNode;
var prevID, currID;
for (var i=0; i<tbody.childNodes.length; i++){
var tr = tbody.childNodes[i];
if (tr===prevSelection){
prevID = i;
}
if (tr===row){
currID = i;
}
}
var selectedRows = [];
for (var i = Math.min(currID, prevID); i <= Math.max(currID, prevID); i++){
var tr = tbody.childNodes[i];
me.select(tr);
if (tr!=row){
rows.push(tr);
}
selectedRows.push(tr);
}
var childNodes = body.getRows();
for (var i=1; i<childNodes.length; i++){
var tr = childNodes[i];
if (tr.selected){
var deselect = true;
for (var j=0; j<selectedRows.length; j++){
var selectedRow = selectedRows[j];
if (tr==selectedRow){
deselect = false;
}
}
if (deselect){
me.deselect(tr);
rows.push(tr);
}
}
}
}
else{
if (e.ctrlKey){
me.select(row);
var childNodes = body.getRows();
for (var i=1; i<childNodes.length; i++){
var tr = childNodes[i];
if (tr.selected && tr!=row){
rows.push(tr);
}
}
}
else{
selectRow();
}
}
}
}
else{
if (row.selected){
me.deselect(row);
}
else {
selectRow();
}
}
me.onRowClick(row, event);
me.onSelectionChange(rows);
prevSelection = row;
};
//**************************************************************************
//** select
//**************************************************************************
/** Used to select a given row.
*/
this.select = function(row){
if (row.selected) return;
row.selected=true;
setStyle(row, "selectedRow");
};
//**************************************************************************
//** deselect
//**************************************************************************
/** Used to deselect a given row.
*/
this.deselect = function(row){
if (row.selected){
row.selected=false;
setStyle(row, "row");
}
};
//**************************************************************************
//** selectAll
//**************************************************************************
/** Selects all the rows in the table.
*/
this.selectAll = function(){
var rows = [];
if (config.multiselect === true){
var childNodes = body.getRows();
for (var i=1; i<childNodes.length; i++){
var tr = childNodes[i];
if (!tr.selected){
me.select(tr);
rows.push(tr);
}
}
prevSelection = null;
if (rows.length) me.onSelectionChange(rows);
}
};
//**************************************************************************
//** deselectAll
//**************************************************************************
/** Deselects all the rows in the table.
*/
this.deselectAll = function(){
var rows = [];
if (body){
var childNodes = body.getRows();
for (var i=1; i<childNodes.length; i++){
var tr = childNodes[i];
if (tr.selected){
me.deselect(tr);
rows.push(tr);
}
}
}
prevSelection = null;
if (rows.length>0) me.onSelectionChange(rows);
};
//**************************************************************************
//** onSelectionChange
//**************************************************************************
/** Called whenever a row in the grid is selected or deselected. Contents of
* the selected rows can be retrieved using the getContent method. Example:
<pre>
table.onSelectionChange = function(rows){
for (var i=0; i<rows.length; i++){
var row = rows[i];
if (row.selected){
//Get content of the first cell
var cells = row.childNodes;
var cell = cells[0].getContent();
//Alternatively, get content via the row.get() method
var cell = row.get(0);
}
else{