forked from chsword/flexigrid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflexigrid.js
1626 lines (1370 loc) · 63.6 KB
/
flexigrid.js
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
/*
* Flexigrid for jQuery - New Wave Grid
*
* Copyright (c) 2008 Paulo P. Marinas (webplicity.net/flexigrid)
* Dual licensed under the MIT (MIT-LICENSE.txt)
* and GPL (GPL-LICENSE.txt) licenses.
*
* $Date: 2008-07-14 00:09:43 +0800 (Tue, 14 Jul 2008) $
*/
(function($){
$.addFlex = function(t,p)
{
if (t.grid) return false; //return if already exist
// apply default properties
p = $.extend({
height: 200, //default height
width: 'auto', //auto width
striped: true, //apply odd even stripes
novstripe: false,
minwidth: 30, //min width of columns
minheight: 80, //min height of columns
resizable: true, //resizable table
colresizable: false,
reorderable: false, //All columns to be moved
url: false, //ajax url
method: 'POST', // data sending method
dataType: 'xml', // type of data loaded
errormsg: 'Connection Error',
usepager: false, //
nowrap: true, //
page: 1, //current page
total: 1, //total pages
useRp: true, //use the results per page select box
rp: 15, // results per page
rpOptions: [10,15,20,25,40],
title: false,
pagestat: 'Displaying {from} to {to} of {total} items',
pagetext: 'Page',
outof: 'of',
findtext: 'Find',
procmsg: 'Processing, please wait ...',
query: '',
qtype: '',
nomsg: 'No items',
minColToggle: 1, //minimum allowed column to be hidden
showToggleBtn: false, //show or hide column toggle popup
hideOnSubmit: true,
autoload: false,
blockOpacity: 0.5,
onToggleCol: false,
onChangeSort: false,
onSuccess: false,
debug: true,
onError: false,
onSubmit: false, // using a custom populate function
prepareRequest: false // Could be used do modify the request data send to target with ajax method.
}, p);
$(t)
.show() //show if hidden
.attr({cellPadding: 0, cellSpacing: 0, border: 0}) //remove padding and spacing
.removeAttr('width') //remove width properties
;
//create grid class
var g = {
hset : {},
data_downloaded: {},
rePosDrag: function () {
var cdleft = 0 - this.hDiv.scrollLeft;
if (this.hDiv.scrollLeft > 0) {
cdleft -= Math.floor(p.cgwidth / 2);
}
$(g.cDrag).css({top:g.hDiv.offsetTop + 1});
var cdpad = this.cdpad;
if (p.colresizable){
// Select all possible drags and hide it. The selection is stored to a variable because
// we will reuse it later while iterate through the header cells.
var qdrags = $('div', g.cDrag);
qdrags.hide();
// We do not use the regular each method of jQuery because we do need the index of the
// header cell for other operation with the drags.
var qheaders = $('thead tr:first th:visible', this.hDiv);
for (var n = 0; n < qheaders.length; n++) {
var cdpos = parseInt($('div', qheaders[n]).width());
if (cdleft == 0) {
cdleft -= Math.floor(p.cgwidth / 2);
}
cdpos = cdpos + cdleft + cdpad;
// Select the drag which is equals to the index of the current header cell.
$(qdrags[n]).css('left', cdpos + 'px').show();
cdleft = cdpos;
}
}
},
fixHeight: function (newH) {
newH = false;
if (!newH) newH = $(g.bDiv).height();
var hdHeight = $(this.hDiv).height();
$('div',this.cDrag).each(
function ()
{
$(this).height(newH+hdHeight);
}
);
var nd = parseInt($(g.nDiv).height());
if (nd>newH)
$(g.nDiv).height(newH).width(200);
else
$(g.nDiv).height('auto').width('auto');
$(g.block).css({height:newH,marginBottom:(newH * -1)});
var hrH = g.bDiv.offsetTop + newH;
if (p.height != 'auto' && p.resizable) hrH = g.vDiv.offsetTop;
$(g.rDiv).css({height: hrH});
},
dragStart: function (dragtype,e,obj) { //default drag function start
if (dragtype=='colresize') //column resize
{
$(g.nDiv).hide();$(g.nBtn).hide();
var n = $('div',this.cDrag).index(obj);
var ow = $('th:visible div:eq('+n+')',this.hDiv).width();
$(obj).addClass('dragging').siblings().hide();
$(obj).prev().addClass('dragging').show();
this.colresize = {startX: e.pageX, ol: parseInt(obj.style.left), ow: ow, n : n };
$('body').css('cursor','col-resize');
}
else if (dragtype=='vresize') //table resize
{
var hgo = false;
$('body').css('cursor','row-resize');
if (obj)
{
hgo = true;
$('body').css('cursor','col-resize');
}
this.vresize = {h: p.height, sy: e.pageY, w: p.width, sx: e.pageX, hgo: hgo};
}
else if (dragtype=='colMove') //column header drag
{
$(g.nDiv).hide();$(g.nBtn).hide();
this.hset = $(this.hDiv).offset();
this.hset.right = this.hset.left + $('table',this.hDiv).width();
this.hset.bottom = this.hset.top + $('table',this.hDiv).height();
this.dcol = obj;
this.dcoln = $('th',this.hDiv).index(obj);
this.colCopy = document.createElement("div");
this.colCopy.className = "colCopy";
this.colCopy.innerHTML = obj.innerHTML;
if ($.browser.msie)
{
this.colCopy.className = "colCopy ie";
}
$(this.colCopy).css({position:'absolute', 'float': 'left', display:'none', textAlign: obj.align});
$('body').append(this.colCopy);
$(this.cDrag).hide();
}
$('body').noSelect();
},
dragMove: function (e) {
if (this.colresize) //column resize
{
var n = this.colresize.n;
var diff = e.pageX-this.colresize.startX;
var nleft = this.colresize.ol + diff;
var nw = this.colresize.ow + diff;
if (nw > p.minwidth)
{
$('div:eq('+n+')',this.cDrag).css('left',nleft);
this.colresize.nw = nw;
}
}
else if (this.vresize) //table resize
{
var v = this.vresize;
var y = e.pageY;
var diff = y-v.sy;
if (!p.defwidth) p.defwidth = p.width;
if (p.width != 'auto' && !p.nohresize && v.hgo)
{
var x = e.pageX;
var xdiff = x - v.sx;
var newW = v.w + xdiff;
if (newW > p.defwidth)
{
this.gDiv.style.width = newW + 'px';
p.width = newW;
}
}
var newH = v.h + diff;
if ((newH > p.minheight || p.height < p.minheight) && !v.hgo)
{
this.bDiv.style.height = newH + 'px';
p.height = newH;
this.fixHeight(newH);
}
v = null;
}
else if (this.colCopy) {
$(this.dcol).addClass('thMove').removeClass('thOver');
if (e.pageX > this.hset.right || e.pageX < this.hset.left || e.pageY > this.hset.bottom || e.pageY < this.hset.top)
{
//this.dragEnd();
$('body').css('cursor','move');
}
else
$('body').css('cursor','pointer');
$(this.colCopy).css({top:e.pageY + 10,left:e.pageX + 20, display: 'block'});
}
},
dragEnd: function () {
if (this.colresize)
{
var n = this.colresize.n;
var nw = this.colresize.nw;
$('th:visible div:eq('+n+')',this.hDiv).css('width',nw);
$('tr',this.bDiv).each (
function ()
{
$('td:visible div:eq('+n+')',this).css('width',nw);
}
);
this.hDiv.scrollLeft = this.bDiv.scrollLeft;
$('div:eq('+n+')',this.cDrag).siblings().show();
$('.dragging',this.cDrag).removeClass('dragging');
this.rePosDrag();
this.fixHeight();
this.colresize = false;
}
else if (this.vresize)
{
this.vresize = false;
}
else if (this.colCopy)
{
$(this.colCopy).remove();
if (this.dcolt != null)
{
if (this.dcoln>this.dcolt)
$('th:eq('+this.dcolt+')',this.hDiv).before(this.dcol);
else
$('th:eq('+this.dcolt+')',this.hDiv).after(this.dcol);
this.switchCol(this.dcoln,this.dcolt);
$(this.cdropleft).remove();
$(this.cdropright).remove();
this.rePosDrag();
}
this.dcol = null;
this.hset = null;
this.dcoln = null;
this.dcolt = null;
this.colCopy = null;
$('.thMove',this.hDiv).removeClass('thMove');
$(this.cDrag).show();
}
$('body').css('cursor','default');
$('body').noSelect(false);
},
toggleCol: function(cid,visible) {
var ncol = $("th[axis='col"+cid+"']",this.hDiv)[0];
var n = $('thead th',g.hDiv).index(ncol);
var cb = $('input[value='+cid+']',g.nDiv)[0];
if (visible==null)
{
visible = ncol.hide;
}
if ($('input:checked',g.nDiv).length<p.minColToggle&&!visible) return false;
if (visible)
{
ncol.hide = false;
$(ncol).show();
cb.checked = true;
}
else
{
ncol.hide = true;
$(ncol).hide();
cb.checked = false;
}
$('tbody tr',t).each
(
function ()
{
if (visible)
$('td:eq('+n+')',this).show();
else
$('td:eq('+n+')',this).hide();
}
);
this.rePosDrag();
if (p.onToggleCol) p.onToggleCol(cid,visible);
return visible;
},
switchCol: function(cdrag,cdrop) { //switch columns
$('tbody tr',t).each
(
function ()
{
if (cdrag>cdrop)
$('td:eq('+cdrop+')',this).before($('td:eq('+cdrag+')',this));
else
$('td:eq('+cdrop+')',this).after($('td:eq('+cdrag+')',this));
}
);
//switch order in nDiv
if (cdrag>cdrop)
$('tr:eq('+cdrop+')',this.nDiv).before($('tr:eq('+cdrag+')',this.nDiv));
else
$('tr:eq('+cdrop+')',this.nDiv).after($('tr:eq('+cdrag+')',this.nDiv));
if ($.browser.msie&&$.browser.version<7.0) $('tr:eq('+cdrop+') input',this.nDiv)[0].checked = true;
this.hDiv.scrollLeft = this.bDiv.scrollLeft;
},
scroll: function() {
this.hDiv.scrollLeft = this.bDiv.scrollLeft;
this.rePosDrag();
},
addData: function (data) { //parse data
this.data_downloaded = data;
if (p.preProcess) {
data = p.preProcess(data);
}
if (!data) {
// There is no data after loading. Interrupt the loading here,
// set busy to to false and display an error message.
g.setBusy(false);
$('.pPageStat',this.pDiv).html(p.errormsg);
return false;
}
if (p.dataType=='xml') {
p.total = +$('rows total',data).text();
} else {
p.total = data.total;
}
if (p.total==0)
{
$('tr, a, td, div',t).unbind();
$(t).empty();
p.pages = 1;
p.page = 1;
this.buildpager();
$('.pPageStat',this.pDiv).html(p.nomsg);
// Deactivate the busy mode.
g.setBusy(false);
// Call the onSuccess hook (if present).
if (p.onSuccess) {
p.onSuccess();
return false;
}
p.pages = Math.ceil(p.total/p.rp);
if (p.dataType=='xml')
p.page = +$('rows page',data).text();
else
p.page = data.page;
this.buildpager();
// Build new body...
var tbody = document.createElement('tbody');
// Select the body before. This is better because this selected jQuery object could be used more then one times in the next steps.
var qtbody = $(tbody);
// If Debugging is enabled record the start time of the rendering process.
if (p.debug) {
var startTime = new Date();
}
/**
* This method is used to finalize the rendering of the data to the body if the grid list.
* @return (void)
*/
function finalizeRendering() {
var qt = $(t);
// Clean the current body compleate and add the new generated body.
$('tr', qt).unbind();
qt.empty();
qt.append(qtbody);
g.rePosDrag();
// This is paranoid but set the variables back to null. It is better for debugging.
tbody = null;
data = null;
// Call the onSuccess hook (if present).
if (p.onSuccess) {
p.onSuccess();
}
// Deactivate the busy mode.
g.setBusy(false);
if (p.debug && window.console && window.console.log) {
// If debugging is enabled log the duration of this operation.
var nowTime = new Date();
console.log('Duration of rendering data of type "' + p.dataType + '": ' + (nowTime - startTime) + 'ms');
}
}
// We will need the header cell at this point more times.
// So we do better to store it not for further usages.
var headers = $('thead tr:first th',g.hDiv);
// What is going on here? Because of many rows we have to render, we do not
// iterate with a regular foreach method. We make a pseudo asynchron process with
// the setTimeout method. We do better to do this because in other way we will
// force a lagging of the whole browser. In the worst case the user will get a
// dialog box of an "endless looping javaScript".
if (p.dataType=='json') {
// Prepare the looping parameters.
var ji = 0;
var row = null;
function doJsonRow() {
// Only if there are more rows we will render a next row.
if (data.rows.length > ji) {
row = data.rows[ji];
// Paranoid I know but it possible that there is an array selected with
// null entries.
if (row) {
var tr = document.createElement('tr');
var qtr = $(tr);
if (ji % 2 && p.striped) {
tr.className = 'erow';
}
if (row.id) {
tr.id = 'row' + row.id;
}
// Add each cell
for (idx = 0; idx < row.cell.length; idx++) {
var td = document.createElement('td');
var th = idx < headers.length ? headers[idx] : null;
if (th) {
td.align = th.align;
}
qtr.append(td);
g.addCellProp(td, qtr, row.cell[idx], th);
}
qtbody.append(tr);
g.addRowProp(qtr);
// Prepare the next step.
tr = null;
ji++;
setTimeout(doJsonRow, 1);
} else {
finalizeRendering();
}
} else {
finalizeRendering();
}
}
// Start the pseudo asynchron iteration.
setTimeout(doJsonRow, 1);
} else if (p.dataType=='xml') {
// Prepare the looping parameters.
var index = 1;
var xi = 0;
var rows = $("rows row", data);
function doXmlRow() {
// Only if there are more rows we will render a next row.
if (xi < rows.length) {
var row = rows[xi];
// Paranoid I know but it possible that there is an array selected with
// null entries.
if (row) {
var qrow = $(row);
index++;
var tr = document.createElement('tr');
var qtr = $(tr);
if (index % 2 && p.striped) {
tr.className = 'erow';
}
var nid = qrow.attr('id');
if (nid) {
tr.id = 'row' + nid;
}
nid = null;
var cells = $('cell', row);
// Add each cell
for (idx = 0; idx < cells.length; idx++) {
var td = document.createElement('td');
var th = idx < headers.length ? headers[idx] : null;
if (th) {
td.align = th.align;
}
qtr.append(td);
g.addCellProp(td, qtr, $(cells[idx]).text(), th);
}
qtbody.append(tr);
// Prepare the next step.
tr = null;
xi++;
setTimeout(doXmlRow, 1);
} else {
finalizeRendering();
}
} else {
finalizeRendering();
}
}
// Start the pseudo asynchron iteration.
setTimeout(doXmlRow, 1);
} else {
throw new Error('DataType "' + p.dataType + '" could not be handled.');
}
},
changeSort: function(th) { //change sortorder
if (this.loading) return true;
$(g.nDiv).hide();$(g.nBtn).hide();
if (p.sortname == $(th).attr('abbr'))
{
if (p.sortorder=='asc') p.sortorder = 'desc';
else p.sortorder = 'asc';
}
$(th).addClass('sorted').siblings().removeClass('sorted');
$('.sdesc',this.hDiv).removeClass('sdesc');
$('.sasc',this.hDiv).removeClass('sasc');
$('div',th).addClass('s'+p.sortorder);
p.sortname= $(th).attr('abbr');
if (p.onChangeSort)
p.onChangeSort(p.sortname,p.sortorder);
else
this.populate();
},
buildpager: function(){ //rebuild pager based on new properties
$('.pcontrol input',this.pDiv).val(p.page);
$('.pcontrol span',this.pDiv).html(p.pages);
var r1 = (p.page-1) * p.rp + 1;
var r2 = r1 + p.rp - 1;
if (p.total<r2) r2 = p.total;
var stat = p.pagestat;
stat = stat.replace(/{from}/,r1);
stat = stat.replace(/{to}/,r2);
stat = stat.replace(/{total}/,p.total);
$('.pPageStat',this.pDiv).html(stat);
},
/**
* This method is used to control the grid busy state.
*
* @param busy if set to true the grid list will get a semi transparent layer, a loading message will be displayed and a spinner.
* If set to false this layer, spinner and message will be removed.
* @return (boolean) true if the state is changed.
*/
setBusy: function (busy) {
var result = false;
if (busy) {
if (!this.loading) {
this.loading = true;
$('.pPageStat',this.pDiv).html(p.procmsg);
$('.pReload',this.pDiv).addClass('loading');
$(g.block).css({top:g.bDiv.offsetTop});
if (p.hideOnSubmit) {
$(this.gDiv).prepend(g.block); //$(t).hide();
}
if ($.browser.opera) {
$(t).css('visibility','hidden');
}
result = true;
}
} else {
if (this.loading) {
var qstatus = $('.pPageStat',this.pDiv);
if (qstatus.html() == p.procmsg) {
$('.pPageStat',this.pDiv).text('');
}
$('.pReload',this.pDiv).removeClass('loading');
if (p.hideOnSubmit) {
$(g.block).remove(); //$(t).show();
}
g.hDiv.scrollLeft = g.bDiv.scrollLeft;
if ($.browser.opera) {
$(t).css('visibility','visible');
}
this.loading = false;
result = true;
}
}
return result;
},
populate: function () { //get latest data
if (this.loading) return true;
if (p.onSubmit)
{
var gh = p.onSubmit();
if (!gh) return false;
}
if (!p.url) return false;
// Make this grid list busy for the user.
this.setBusy(true);
if (!p.newp) p.newp = 1;
if (p.page>p.pages) p.page = p.pages;
//var param = {page:p.newp, rp: p.rp, sortname: p.sortname, sortorder: p.sortorder, query: p.query, qtype: p.qtype};
var data = [];
var params = [
{ name : 'page', value : p.newp }
,{ name : 'rp', value : p.rp }
,{ name : 'sortname', value : p.sortname}
,{ name : 'sortorder', value : p.sortorder }
,{ name : 'query', value : p.query}
,{ name : 'qtype', value : p.qtype}
];
// Only add parameters to request data which are not null.
for (i in params) {
var param = params[i];
if (param && param.name && param.value) {
data.push(param);
}
}
// If there are some additional parameters and each are not null add it to the request data.
if (p.params) {
for (pi in p.params) {
var current = p.params[pi];
if (current && current.name && current.value) {
data.push(current);
}
}
}
// Call prepareRequest hook.
if (p.prepareRequest) {
p.prepareRequest(data);
}
$.ajax({
type: p.method,
url: p.url,
data: data,
dataType: p.dataType,
success: function(data){g.addData(data);},
error: function(XMLHttpRequest, textStatus, errorThrown) {
try {
g.setBusy(false);
if (p.onError)
p.onError(XMLHttpRequest, textStatus, errorThrown);
} catch (e) {}
return false;
}
});
},
doSearch: function () {
p.query = $('input[name=q]',g.sDiv).val();
p.qtype = $('select[name=qtype]',g.sDiv).val();
p.newp = 1;
this.populate();
},
changePage: function (ctype){ //change page
if (this.loading) return true;
switch(ctype)
{
case 'first': p.newp = 1; break;
case 'prev': if (p.page>1) p.newp = parseInt(p.page) - 1; break;
case 'next': if (p.page<p.pages) p.newp = parseInt(p.page) + 1; break;
case 'last': p.newp = p.pages; break;
case 'input':
var nv = parseInt($('.pcontrol input',this.pDiv).val());
if (isNaN(nv)) nv = 1;
if (nv<1) nv = 1;
else if (nv > p.pages) nv = p.pages;
$('.pcontrol input',this.pDiv).val(nv);
p.newp =nv;
break;
}
if (p.newp==p.page) return false;
if (p.onChangePage)
p.onChangePage(p.newp);
else
this.populate();
},
addCellProp: function (cell, prnt, innerHtml, pth) {
var tdDiv = document.createElement('div');
var qtdDiv = $(tdDiv);
var qcell = $(cell);
if (pth != null) {
/*
if (p.sortname == $(pth).attr('abbr') && p.sortname) {
cell.className = 'sorted';
}
*/
qtdDiv.css({textAlign:pth.align,width: $('div:first', pth)[0].style.width});
if (pth.hide) {
qcell.css('display', 'none');
}
}
if (p.nowrap == false) {
qtdDiv.css('white-space', 'normal');
}
if (!innerHtml || innerHtml == '') {
innerHtml = ' ';
}
tdDiv.innerHTML = innerHtml;
var pid = false;
if (prnt.id) {
pid = prnt.id.substr(3);
}
if (pth != null && pth.process) {
pth.process(tdDiv, pid);
}
qcell.empty().append(tdDiv).removeAttr('width');
},
getCellDim: function (obj) // get cell prop for editable event
{
var ht = parseInt($(obj).height());
var pht = parseInt($(obj).parent().height());
var wt = parseInt(obj.style.width);
var pwt = parseInt($(obj).parent().width());
var top = obj.offsetParent.offsetTop;
var left = obj.offsetParent.offsetLeft;
var pdl = parseInt($(obj).css('paddingLeft'));
var pdt = parseInt($(obj).css('paddingTop'));
return {ht:ht,wt:wt,top:top,left:left,pdl:pdl, pdt:pdt, pht:pht, pwt: pwt};
},
addRowProp: function(qrow) {
qrow.click(function (e) {
var obj = (e.target || e.srcElement);
if (obj.href || obj.type) {
return true;
}
$(this).toggleClass('trSelected');
if (p.singleSelect) {
qrow.siblings().removeClass('trSelected');
}
}).mousedown(function (e) {
if (e.shiftKey) {
$(this).toggleClass('trSelected');
g.multisel = true;
this.focus();
$(g.gDiv).noSelect();
}
}).mouseup(function () {
if (g.multisel) {
g.multisel = false;
$(g.gDiv).noSelect(false);
}
}).hover(function () {
if (g.multisel) {
$(this).toggleClass('trSelected');
}
}, function () {
});
if ($.browser.msie && $.browser.version < 7.0) {
qrow.hover(function () {
$(this).addClass('trOver');
}, function () {
$(this).removeClass('trOver');
});
}
},
pager: 0
};
//create model if any
if (p.colModel)
{
thead = document.createElement('thead');
tr = document.createElement('tr');
for (i=0;i<p.colModel.length;i++)
{
var cm = p.colModel[i];
var th = document.createElement('th');
th.innerHTML = cm.display;
if (cm.name&&cm.sortable)
$(th).attr('abbr',cm.name);
//th.idx = i;
$(th).attr('axis','col'+i);
if (cm.align)
th.align = cm.align;
if (cm.width)
$(th).attr('width',cm.width);
if (cm.hide)
{
th.hide = true;
}
if (cm.process)
{
th.process = cm.process;
}
$(tr).append(th);
}
$(thead).append(tr);
$(t).prepend(thead);
} // end if p.colmodel
//init divs
g.gDiv = document.createElement('div'); //create global container
g.mDiv = document.createElement('div'); //create title container
g.hDiv = document.createElement('div'); //create header container
g.bDiv = document.createElement('div'); //create body container
g.vDiv = document.createElement('div'); //create grip
g.rDiv = document.createElement('div'); //create horizontal resizer
g.cDrag = document.createElement('div'); //create column drag
g.block = document.createElement('div'); //creat blocker
g.nDiv = document.createElement('div'); //create column show/hide popup
g.nBtn = document.createElement('div'); //create column show/hide button
g.iDiv = document.createElement('div'); //create editable layer
g.tDiv = document.createElement('div'); //create toolbar
g.sDiv = document.createElement('div');
if (p.usepager) g.pDiv = document.createElement('div'); //create pager container
g.hTable = document.createElement('table');
//set gDiv
g.gDiv.className = 'flexigrid';
if (p.width!='auto') g.gDiv.style.width = p.width + 'px';
//add conditional classes
if ($.browser.msie)
$(g.gDiv).addClass('ie');
if (p.novstripe)
$(g.gDiv).addClass('novstripe');
$(t).before(g.gDiv);
$(g.gDiv)
.append(t)
;
//set toolbar
if (p.buttons)
{
g.tDiv.className = 'tDiv';
var tDiv2 = document.createElement('div');
tDiv2.className = 'tDiv2';
for (i=0;i<p.buttons.length;i++)
{
var btn = p.buttons[i];
if (!btn.separator)
{
var btnDiv = document.createElement('div');
btnDiv.className = 'fbutton';
btnDiv.innerHTML = "<div><span>"+btn.name+"</span></div>";
if (btn.bclass)
$('span',btnDiv)
.addClass(btn.bclass)
.css({paddingLeft:20})
;
btnDiv.onpress = btn.onpress;
btnDiv.name = btn.name;
if (btn.onpress)
{
$(btnDiv).click
(
function ()
{
this.onpress(this.name,g.gDiv);
}
);
}
$(tDiv2).append(btnDiv);
if ($.browser.msie&&$.browser.version<7.0)
{
$(btnDiv).hover(function(){$(this).addClass('fbOver');},function(){$(this).removeClass('fbOver');});
}
} else {
$(tDiv2).append("<div class='btnseparator'></div>");
}
}
$(g.tDiv).append(tDiv2);
$(g.tDiv).append("<div style='clear:both'></div>");
$(g.gDiv).prepend(g.tDiv);
}
//set hDiv
g.hDiv.className = 'hDiv';
$(t).before(g.hDiv);
//set hTable
g.hTable.cellPadding = 0;
g.hTable.cellSpacing = 0;
$(g.hDiv).append('<div class="hDivBox"></div>');
$('div',g.hDiv).append(g.hTable);
var thead = $("thead:first",t).get(0);
if (thead) $(g.hTable).append(thead);
thead = null;
if (!p.colmodel) var ci = 0;
//setup thead
$('thead tr:first th',g.hDiv).each
(
function ()
{
var thdiv = document.createElement('div');
if ($(this).attr('abbr'))
{
$(this).click(
function (e)
{