-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataGrid.js
More file actions
1796 lines (1433 loc) · 56.1 KB
/
DataGrid.js
File metadata and controls
1796 lines (1433 loc) · 56.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
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={};
//******************************************************************************
//** DataGrid
//******************************************************************************
/**
* Scrollable table with a fixed header. Supports remote loading, sorting,
* and infinite scroll via HTTP.
* <br/>
* Here's a simple example of how to instantiate a DataGrid that will render
* a list of users returned from a REST endpoint:
<pre>
var grid = new javaxt.dhtml.DataGrid(parent, {
//Set style
style: config.style.table,
//Define columns
columns: [
{header: 'ID', hidden:true},
{header: 'Name', width:'100%'},
{header: 'Role', width:'240'},
{header: 'Enabled', width:'75', align:'center'},
{header: 'Last Active', width:'175', align:'right'}
],
//Set path to REST endpoint to get list of users
url: "/manage/users",
//Define function used to parse the response
parseResponse: function(request){
return JSON.parse(request.responseText);
},
//Define function used to render data for individual rows
update: function(row, user){
row.set('Name', user.fullname);
row.set('Role', user.role);
var status = user.status;
if (status===1){
row.set('Enabled', createElement("i", "fas fa-check"));
}
},
//Set flag to automatically load data once the component is rendered
autoload: true
});
</pre>
* Once the grid is instantiated you can call any of the public methods. You
* can also add event listeners by overriding any of the public "on" or
* "before" methods like this:
<pre>
grid.onRowClick = function(row, e){
console.log(row.record);
};
</pre>
*
******************************************************************************/
javaxt.dhtml.DataGrid = function(parent, config) {
this.className = "javaxt.dhtml.DataGrid";
var me = this;
var table;
var mask;
var currPage = 1;
var eof = false;
var pageRequests = {};
var loading = false;
var checkboxHeader;
var columns;
var rowHeight; //<-- Assumes all the rows are the same height!
//Legacy config parameters
var filterName, filter;
//Create default style
var defaultStyle = {};
if (javaxt.dhtml.style){
if (javaxt.dhtml.style.default){
var tableStyle = javaxt.dhtml.style.default.table;
if (tableStyle){
defaultStyle = tableStyle;
var checkboxStyle = javaxt.dhtml.style.default.checkbox;
defaultStyle.checkbox = checkboxStyle;
}
}
}
//Set default config
var defaultConfig = {
/** Style config. See default styles in javaxt.dhtml.Table for a list of
* options. In addition to the table styles, you can also specify a
* checkbox style.
*/
style: defaultStyle,
/** Used to define columns to display. Each entry in the array should
* include a "header" label (see example above) along with a "width".
* Note that one of the columns should have a width of 100%. Additional
* options include "align" and "field". If a "field" is provided it will
* be used to construct a "fields" parameter to that is sent to the
* server (see "fields" config). Fially, you can specify a checkbox
* column by setting the "header" to "x" (e.g. header: 'x'). If a
* checkbox column is defined, a checkbox will be created in the header
* and in individual rows. The checkbox is typically used to support
* multi-select operations.
*/
columns: [],
/** The URL endpoint that this component uses to fetch records
*/
url: "",
/** JSON object with key/value pairs that are appended to the URL
*/
params: null,
/** Data to send in the body of the request. This parameter is optional.
* If payload is not null, the component executes a POST request.
*/
payload: null,
/** If true, and if the payload is empty, will sent params as a URL
* encoded string in a POST request. Otherwise the params will be
* appended to the query string in the request URL. Default is false.
*/
post: false,
/** Used to specify the page size (i.e. the maximum number records to
* fetch from the server at a time). Default is 50.
*/
limit: 50,
/** If true, the server will be asked to return a total record count by
* setting the "count" parameter to true when requesting the first page.
* Otherwise, the count parameter is set to false. Note that the count
* is NOT required for pagination and is not used internally in any way.
* Rather it is for informational purposes only. Default is false.
*/
count: false,
/** If true, the grid will automatically fetch records from the server
* on start-up. Default is false.
*/
autoload: false,
/** If true, the grid will sort values in the grid locally using whatever
* data is available. If fetching data from a remote server, recommend
* setting localSort to false (default)
*/
localSort: false,
/** Optional list of field names used to specify which database fields
* should be returned from the server. If not provided, uses the "field"
* attributes in the column definition. If both are provided, the list
* of fields are merged into a unique list.
*/
fields: [],
/** If true, will hide the header row. Default is false.
*/
hideHeader: false,
/** 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,
/** Default method used to get responses from the server. Typically, you
* do not need to override this method.
*/
getResponse: function(url, payload, callback){
//Transform GET request into POST request if possible. This will
//tidy up the URLs and reduce log size
var contentType;
if (!payload && config.post==true){
contentType = "application/x-www-form-urlencoded";
var idx = url.indexOf("?");
if (idx>-1){
payload = url.substring(idx+1);
url = url.substring(0, idx);
}
}
//Get response
javaxt.dhtml.utils.get(url, {
payload: payload,
contentType: contentType,
success: function(text, xml, url, request){
callback.apply(me, [request]);
},
failure: function(request){
callback.apply(me, [request]);
}
});
},
/** Default method used to parse responses from the server. Should return
* an array of rows with an array of values in each row. Example:
* [["Bob","12/30","$5.25"],["Jim","10/28","$7.33"]]
*/
parseResponse: function(request){
return [];
},
/** Default method used to update a row with values. This method can be
* overridden to render values in a variety of different ways (e.g.
* different fonts, links, icons, etc). The row.set() method accepts
* strings, numbers, and DOM elements.
*/
update: function(row, record){
for (var i=0; i<record.length; i++){
row.set(i, record[i]);
}
},
/** DOM element with custom show() and hide() methods. The mask is
* typically rendered over the grid control to prevent users from
* interacting with the grid during load events. It is rendered before
* load and is hidden after data is rendered. If a mask is not defined,
* a simple mask will be created automatically using the "mask" style
* config.
*/
mask: null
};
//**************************************************************************
//** Constructor
//**************************************************************************
var init = function(){
//Merge config with default config
config = merge(config, defaultConfig);
//Extract required config variables
filterName = config.filterName;
if (config.sort==="local") config.localSort = true;
if (config.fields){
if (!isArray(config.fields)){
config.fields = config.fields.split(",");
}
}
else{
config.fields = [];
}
//Parse column config
var multiselect = config.multiselect;
columns = [];
for (var i=0; i<config.columns.length; i++){
var column = config.columns[i];
//Set "fields" class variable
if (column.field){
var addField = true;
for (var j=0; j<config.fields.length; j++){
if (config.fields[j]==column.field){
addField = false;
break;
}
}
if (addField) config.fields.push(column.field);
}
else{
//Don't allow remote sorting on columns without a field name
if (config.localSort!==true){
column.sortable = false;
}
}
//Clone the column config
var clone = {};
for (var p in column) {
if (column.hasOwnProperty(p)) {
clone[p] = column[p];
}
}
//Update "header" setting in the column config
var header = column.header;
if (header==='x' && !checkboxHeader){
clone.header = createCheckbox();
var checkbox = clone.header.checkbox;
checkboxHeader = {
idx: i,
isChecked: checkbox.isChecked,
check: checkbox.select,
uncheck: checkbox.deselect
};
}
else{
clone.header = createHeader(header, column.sortable);
}
columns.push(clone);
}
//Update column config using the "sort" filter
setFilter(config.filter);
//Create table
table = new javaxt.dhtml.Table(parent, {
multiselect: multiselect,
hideHeader: config.hideHeader,
columns: columns,
style: config.style
});
table.el.className = "javaxt-datagrid";
me.el = table.el;
//Get mask
mask = config.mask;
if (!mask) mask = table.getMask();
//Add load function to the table
table.load = function(records, append){
if (!append) me.clear();
var rows = table.addRows(records.length);
var select = false;
if (checkboxHeader){
select = checkboxHeader.isChecked();
}
var isDataStore = (records instanceof javaxt.dhtml.DataStore);
for (var i=0; i<rows.length; i++){
//Assign the record to the row
rows[i].record = isDataStore ? records.get(i) : records[i];
//Override the update method
rows[i].update = function(){
config.update(this, this.record);
};
//Override the native "set" method on the row
rows[i]._set = rows[i].set;
rows[i].set = function(key, val){
if (key==='x'){
//Create checkbox
for (var j=0; j<config.columns.length; j++){
if (config.columns[j].header==='x'){
var field = config.columns[j].field;
var col = this.childNodes[j];
var obj = col.getContent();
if (obj){
//Column has a checkbox already?
}
else{
val = field ? this.record[field] : this.record;
var checkboxDiv = createCheckbox(val, this);
var checkbox = checkboxDiv.checkbox;
if (select) checkbox.select();
this._set(j, checkboxDiv);
}
return;
}
}
}
else{
//Wrap value in an overflow div as requested
for (var j=0; j<config.columns.length; j++){
if (config.columns[j].header===key && config.columns[j].wrap===true){
val = wrap(val);
break;
}
}
this._set(key, val);
}
};
//Override the native "onclick" method on the row
rows[i]._onclick = rows[i].onclick;
rows[i].onclick = function(e){
//Special case for columns with checkboxes
if (checkboxHeader){
//Check if the client clicked inside a checkbox
var insideCheckbox = false;
var checkboxCol = this.childNodes[checkboxHeader.idx];
var checkbox = checkboxCol.getContent().checkbox;
var rect = _getRect(checkbox.el);
var clientX = e.clientX;
var clientY = e.clientY;
if (clientX>=rect.left && clientX<=rect.right){
if (clientY>=rect.top && clientY<=rect.bottom){
insideCheckbox = true;
}
}
if (insideCheckbox){
//Update checkbox header
if (checkbox.isChecked()){
//Count number of rows that are selected
var numRows = 0;
var checkedItems = 0;
var rows = this.parentNode.childNodes;
for (var i=1; i<rows.length; i++){ //skip phantom row
numRows++;
var checkboxCol = rows[i].childNodes[checkboxHeader.idx];
if (checkboxCol.getContent().checkbox.isChecked()){
checkedItems++;
}
}
//Check the checkbox header as needed
if (checkedItems===numRows){
checkboxHeader.check();
}
}
else{
//Uncheck the checkbox header
checkboxHeader.uncheck();
}
}
else{
if (!e.ctrlKey && !e.shiftKey){
var numSelectedRows = 0;
table.forEachRow(function (row) {
if (row.selected){
numSelectedRows++;
if (numSelectedRows>1){
//Update the click event to simulate a ctrl+click
e = new MouseEvent("click", {
isTrusted: e.isTrusted,
view: e.view,
bubbles: e.bubbles,
cancelable: e.cancelable,
clientX: e.clientX,
clientY: e.clientY,
screenX: e.screenX,
screenY: e.screenY,
altKey: e.altKey,
ctrlKey: true
});
//Exit forEachRow
return true;
}
}
});
}
}
}
this._onclick(e);
};
//Update the row
rows[i].update();
}
if (!append) table.update();
};
//Watch for selection change events
table.onSelectionChange = function(rows){
me.onSelectionChange();
};
//Watch for scroll events
table.onScroll = function(y, maxY, h){
//Calculate start and end rows
var startRow = Math.ceil(y/rowHeight);
if (startRow==0) startRow = 1;
var endRow = Math.ceil((y+h)/rowHeight);
var prevPage = currPage;
setPage(Math.ceil(endRow/config.limit));
//console.log(startRow + "/" + endRow + " (Page: " + currPage + ")");
var d = Math.abs(maxY-y);
if (d<rowHeight){ //if (y===maxY){
if (!eof){
if (currPage===prevPage) setPage(currPage+1);
load(currPage);
}
}
me.onScroll();
};
//Watch for header click events
table.onHeaderClick = sort;
//Watch for row click events
table.onRowClick = function(row, e){
me.onRowClick(row, e);
};
//Watch for key events
table.onKeyEvent = function(keyCode, modifiers){
me.onKeyEvent(keyCode, modifiers);
};
//Load records
if (config.autoload===true) load();
};
//**************************************************************************
//** setFilter
//**************************************************************************
/** Used to update the filter with new params
* @deprecated The filter object is a legacy feature and will be removed
*/
this.setFilter = function(newFilter){
console.warn(
"The filter object in the javaxt.dhtml.DataGrid class is a legacy " +
"feature and will be removed in the future.");
setFilter(newFilter);
};
var setFilter = function(newFilter){
if (!newFilter) newFilter = {};
if (!filter) filter = newFilter;
//Remove duplicates from newFilter
removeDuplicateParams(newFilter);
for (var key in newFilter) {
if (newFilter.hasOwnProperty(key)) {
filter[key] = newFilter[key];
}
}
var deletions = [];
for (var key in filter) {
if (filter.hasOwnProperty(key)) {
if (newFilter[key]===null || newFilter[key]==='undefined'){
deletions.push(key);
}
}
}
for (var i=0; i<deletions.length; i++){
var key = deletions[i];
delete filter[key];
}
for (var j=0; j<columns.length; j++){
columns[j].sort = null;
var colHeader = columns[j].header;
if (colHeader.setSortIndicator) colHeader.setSortIndicator(null);
}
if (filter.orderby){
var arr = filter.orderby.split(",");
for (var i=0; i<arr.length; i++){
var field = arr[i].trim();
if (field.length>0){
var fieldName, sortDirection;
field = field.toUpperCase();
if (field.endsWith(" ASC") || field.endsWith(" DESC")){
var x = field.lastIndexOf(" ");
fieldName = field.substring(0, x).trim();
sortDirection = field.substring(x).trim();
}
else{
fieldName = field;
sortDirection = "ASC";
}
for (var j=0; j<columns.length; j++){
if (columns[j].field){
if (columns[j].field.toUpperCase() === fieldName){
columns[j].sort = sortDirection;
var colHeader = columns[j].header;
if (colHeader.setSortIndicator){
colHeader.setSortIndicator(sortDirection);
}
break;
}
}
}
}
}
}
};
//**************************************************************************
//** getFilter
//**************************************************************************
/** Returns the current filter
* @deprecated The filter object is a legacy feature and will be removed
*/
this.getFilter = function(){
console.warn(
"The filter object in the javaxt.dhtml.DataGrid class is a legacy " +
"feature and will be removed in the future.");
return filter;
};
//**************************************************************************
//** getParams
//**************************************************************************
this.getParams = function(){
return config.params;
};
//**************************************************************************
//** setPage
//**************************************************************************
/** Used to set the currPage variable and call the onPageChange method.
*/
var setPage = function(page){
if (isNaN(page) || page<1) page = 1;
if (page!=currPage){
var prevPage = currPage;
currPage = page;
me.onPageChange(currPage, prevPage);
}
};
//**************************************************************************
//** getCurrPage
//**************************************************************************
/** Returns the current page number
*/
this.getCurrPage = function(){
return currPage;
};
//**************************************************************************
//** getScrollInfo
//**************************************************************************
/** Returns scroll position and dimenstions for the visible area.
*/
this.getScrollInfo = function(){
return table.getScrollInfo();
};
//**************************************************************************
//** enableScroll
//**************************************************************************
/** Used to enable scrolling.
*/
this.enableScroll = function(){
table.enableScroll();
};
//**************************************************************************
//** disableScroll
//**************************************************************************
/** Used to disable scrolling.
*/
this.disableScroll = function(){
table.disableScroll();
};
//**************************************************************************
//** isScrollEnabled
//**************************************************************************
/** Returns true if scrolling is enabled.
*/
this.isScrollEnabled = function(){
return table.isScrollEnabled();
};
//**************************************************************************
//** Events
//**************************************************************************
/** Called whenever the client scrolls within the table. */
this.onScroll = function(){};
/** Called whenever the table advances to the next page of records or
* scrolls to a previous page. */
this.onPageChange = function(currPage, prevPage){};
this.onSelectionChange = function(){};
/** Called immediately before fetching records from the server. */
this.beforeLoad = function(page){};
/** Called immediately after fetching records from the server. */
this.onLoad = function(){};
/** Called whenever there is an issue fetching records from the server. */
this.onError = function(request){};
/** Called whenever the client clicks or taps on a row in the table. */
this.onRowClick = function(row, e){};
/** Called whenever a keyboard event is initiated from the table. */
this.onKeyEvent = function(keyCode, modifiers){};
/** Called whenever a client clicks on a checkbox, either in the header or
* one of the rows. Columns with checkboxes are defined in the "columns"
* config (e.g. header: 'x'),
*/
this.onCheckbox = function(value, checked, checkbox){};
/** Called whenever a client clicks on a header. */
this.onSort = function(idx, sortDirection){};
//**************************************************************************
//** forEachRow
//**************************************************************************
/** Used to traverse all the rows in the table using a callback function.
* The first argument in the callback is a DOM element with a record.
* Example:
<pre>
grid.forEachRow(function(row){
console.log(row, row.record);
});
</pre>
*
* Note that you can return true in the callback function if you wish to
* stop processing rows. Example:
<pre>
grid.forEachRow(function(row, content){
//Do something with the row
//Stop iterating once some contition is met
if (1>0) return true;
});
</pre>
*/
this.forEachRow = function(callback){
table.forEachRow(callback);
};
//**************************************************************************
//** select
//**************************************************************************
/** Used to select a given row in the grid
*/
this.select = function(row){
table.select(row);
};
//**************************************************************************
//** selectAll
//**************************************************************************
/** Selects all the rows in the grid
*/
this.selectAll = function(){
table.selectAll();
};
//**************************************************************************
//** deselectAll
//**************************************************************************
/** Deselects all the rows in the grid
*/
this.deselectAll = function(){
table.deselectAll();
};
//**************************************************************************
//** clear
//**************************************************************************
/** Removes all the rows from the grid
*/
this.clear = function(){
table.clear();
currPage = 1;
pageRequests = {};
if (checkboxHeader) checkboxHeader.uncheck();
};
//**************************************************************************
//** remove
//**************************************************************************
/** Removes a row from the grid
*/
this.remove = function(row){
table.removeRow(row);
};
//**************************************************************************
//** show
//**************************************************************************
/** Used to unhide the grid if it is hidden
*/
this.show = function(){
table.show();
};
//**************************************************************************
//** hide
//**************************************************************************
/** Used to hide the grid
*/
this.hide = function(){
table.hide();
};
//**************************************************************************
//** focus
//**************************************************************************
/** Used to set browser focus on the table.
*/
this.focus = function(){
table.focus();
};
//**************************************************************************
//** refresh
//**************************************************************************
/** Used to clear the grid and reload the first page.
* @param callback Optional callback function called after the grid has
* been refreshed and loaded with data.
*/
this.refresh = function(callback){
me.clear();
//eof = false;
setPage(1);
load(1, callback);
};
//**************************************************************************
//** load
//**************************************************************************
/** Used to load records from the remote store. Optionally, you can pass an
* array of records, along with a page number, to append rows to the table.
*/
this.load = function(){
if (arguments.length>0){
var records = arguments[0];
var page = 1;
if (arguments.length>1) page = parseInt(arguments[1]);
if (isNaN(page) || page<1) page = 1;
if (isArray(records) || records instanceof javaxt.dhtml.DataStore){
me.beforeLoad(page);
table.load(records, page>1);
setPage(page);
calculateRowHeight();
if (arguments.length===1){
eof = true;
}
else{ //caller provided a page number
if (records.length<config.limit) eof = true;
}
me.onLoad();
}
}
else{
load();
}
};
//**************************************************************************
//** setLimit
//**************************************************************************
/** Used to update the number of records to load per page.
*/
this.setLimit = function(limit){
config.limit = limit;
};
//**************************************************************************
//** scrollTo
//**************************************************************************
/** Scrolls to the top of a page or to a row in the table
* @param obj Page number (integer) or row in the grid (DOM element)
*/
this.scrollTo = function(obj){
if (isElement(obj)){
var y = 0;
table.forEachRow(function (row) {
if (row==obj){
return true;
}
y += row.offsetHeight;
});
table.scrollTo(0, y);
return;
}
if (!isNumber(obj)) return;
var page = parseInt(obj);
//Calculate scroll
var y = ((page-1)*config.limit)*rowHeight;
if (y<0) y = 0;
//Check whether the page is already loaded in the grid
var numPagesInGrid = Math.ceil(table.getRowCount()/config.limit);
if (page>numPagesInGrid){
if (page==numPagesInGrid+1){
//Caller wants to jumpt to the next available page.
//Load the page and scroll when ready.
load(page, function(){
table.scrollTo(0, y);
});
}
else{