-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathDW.VCL.JQGrid.pas
1231 lines (1099 loc) · 39.7 KB
/
DW.VCL.JQGrid.pas
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
unit DW.VCL.JQGrid;
interface
uses System.Classes, System.SysUtils, System.Math, StrUtils, DB, DW.VCL.Labels,
DWElementTag;
type
TBsJQGSortOrder = (bsgSortAsc, bsgSortDesc);
TBsJQGPagPosition = (bsgPagTop, bsgPagBottom, bsgPagBoth);
TBsColDataAlign = (bscAlDefault, bscAlLeft, bscAlRight, bscAlCenter);
// TBsColDataVertAlign = (bscAlVerTop, bscAlVerBottom, bscAlVerMiddle);
TbsJQGColInputType = (bsjqgText, bsjqgSelect, bsjqgCustom);
TDWGridColumn = class(TCollectionItem)
private
FFieldName: string;
FTitle: string;
FCSSclass: string;
FDataAlign: TBsColDataAlign;
FHeaderAlign: TBsColDataAlign;
// FFooterAlign: TBsColDataAlign;
// FDataVertAlign: TBsColDataVertAlign;
FWidth: string;
FSortable: Boolean;
FInputType: TbsJQGColInputType;
FResizable: Boolean;
FVisible: Boolean;
FEditable: Boolean;
procedure SetFieldName(const Value: string);
procedure SetTitle(const Value: string);
procedure SetCSSclass(const Value: string);
procedure SetDataAlign(const Value: TBsColDataAlign);
procedure SetHeaderAlign(const Value: TBsColDataAlign);
// procedure SetFooterAlign(const Value: TBsColDataAlign);
// procedure SetDataVertAlign(const Value: TBsColDataVertAlign);
procedure SetWidth(const Value: string);
procedure SetSortable(const Value: Boolean);
function IsWidthStored: Boolean;
function IsCssClassStored: Boolean;
procedure SetInputType(const Value: TbsJQGColInputType);
procedure SetResizable(const Value: Boolean);
procedure SetVisible(const Value: Boolean);
procedure SetEditable(const Value: Boolean);
public
constructor Create(Collection: TCollection); override;
destructor Destroy; override;
published
// The Dataset Field for column
property FieldName: string read FFieldName write SetFieldName;
// the title of Column
property Title: string read FTitle write SetTitle;
// the css class for all cell in this column
property CSSclass: string read FCSSclass write SetCSSclass stored IsCssClassStored;
// the alignament data in all cell in this column
property DataAlign: TBsColDataAlign read FDataAlign write SetDataAlign default bscAlDefault;
// property DataVertAlign:TBsColDataVertAlign read FDataVertAlign write SetDataVertAlign default bscAlVerMiddle;
// the alignament of header tittle
property HeaderAlign: TBsColDataAlign read FHeaderAlign write SetHeaderAlign
default bscAlCenter;
// property FooterAlign: TBsColDataAlign read FFooterAlign write SetFooterAlign default bscAlLeft;
// the width of column in px or %
property Width: string read FWidth write SetWidth stored IsWidthStored;
// if Column is sortable or not
property Sortable: Boolean read FSortable write SetSortable default True;
// if column is editable or not
property Editable: Boolean read FEditable write SetEditable default True;
// the input type for column in edit mode. Require Editable = True;
property InputType: TbsJQGColInputType read FInputType write SetInputType;
// if the column is resizable in browser
property Resizable: Boolean read FResizable write SetResizable default True;
// if the column is visible
property Visible: Boolean read FVisible write SetVisible default True;
end;
TDWJQGrid = class(TDWText)
private
FColumns: TOwnedCollection;
FPagination: Boolean;
FMobileResponsive: Boolean;
FFormatData: TFormatSettings;
FSortColumn: string;
FSortOrder: TBsJQGSortOrder;
FShowHeader: Boolean;
FShowFooter: Boolean;
FShowRefresh: Boolean;
FPaginationPosition: TBsJQGPagPosition;
FclickToSelect: Boolean;
FSingleSelect: Boolean;
data: string;
FGroupingField: string;
FGroupSummary: Boolean;
FGroupCollapse: Boolean;
FGroupLabel: string;
FKeyField: string;
FRowNum: Integer;
procedure SetTagType(const Value: string);
function IsTagTypeStored: Boolean;
function IsSortFieldNameStored: Boolean;
procedure SetColumns(const Value: TOwnedCollection);
// to update script JQGrid options when Component options are changed
procedure UpdateOptions;
// if no columns set an datasource is setted, add all dataset columns
procedure VerifyColumns;
procedure SetMobileResponsive(const Value: Boolean);
procedure SetPagination(const Value: Boolean);
// this event we return a json with the rows that the bootstrap JQGrid request
procedure DbJQGridCustomRestEvents0RestEvent(aParams: TStrings; var aReply: string);
function GetColumns: TOwnedCollection;
function GetTagType: string;
procedure SetSortColumn(const Value: string);
procedure SetSortOrder(const Value: TBsJQGSortOrder);
procedure SetShowHeader(const Value: Boolean);
procedure SetShowFooter(const Value: Boolean);
procedure SetShowRefresh(const Value: Boolean);
procedure SetPaginationPosition(const Value: TBsJQGPagPosition);
procedure SetclickToSelect(const Value: Boolean);
procedure SetSingleSelect(const Value: Boolean);
procedure SetGroupingField(const Value: string);
procedure SetGroupCollapse(const Value: Boolean);
procedure SetGroupSummary(const Value: Boolean);
procedure SetGroupLabel(const Value: string);
procedure DoOnRowSel(aParams: TStrings; var aReply: string);
procedure DoEditRow(aParams: TStrings; var aReply: string);
procedure SetKeyField(const Value: string);
// To Set Intaernal Datasource
procedure SetDataSource(const Value: TDataSource); override;
procedure SetRowNum(const Value: Integer);
protected
procedure InternalRenderScript(const AHTMLName: string; AScript: TStringList); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
function RenderAsync: TDWElementXHTMLTag; override;
function RenderHTML: TDWElementTag; override;
published
property TagType: string read GetTagType write SetTagType stored IsTagTypeStored;
property ScriptInsideTag default False;
// Collection of Columns in the grid.
// To acess Columns.Items[n] properties do a TypeCast eg: TIWBSJQGridColumn(Columns.Items[n]).FieldName
property Columns: TOwnedCollection read GetColumns write SetColumns;
// property Pagination: Boolean read FPagination write SetPagination default True;
// property MobileResponsive: Boolean read FMobileResponsive write SetMobileResponsive default True;
// property SortFieldName:string read FSortColumn write SetSortColumn stored IsSortFieldNameStored;
// property SortOrder: TBsJQGSortOrder read FSortOrder write SetSortOrder default bsgSortAsc;
// property ShowHeader: Boolean read FShowHeader write SetShowHeader default True;
// property ShowFooter:Boolean read FShowFooter write SetShowFooter default False;
// property ShowRefresh:Boolean read FShowRefresh write SetShowRefresh default True;
// property PaginationPosition:TBsJQGPagPosition read FPaginationPosition write SetPaginationPosition default bsgPagBottom;
// property ClickToSelect:Boolean read FclickToSelect write SetclickToSelect default True;
// property SingleSelect:Boolean read FSingleSelect write SetSingleSelect default True;
// Field name for Grouping rows
property GroupingField: string read FGroupingField write SetGroupingField;
// To show group summary, require GroupingField;
property GroupSummary: Boolean read FGroupSummary write SetGroupSummary default False;
// To show group rows collapsed, require GroupingField;
property GroupCollapse: Boolean read FGroupCollapse write SetGroupCollapse default False;
// Text to show before group header value
property GroupLabel: string read FGroupLabel write SetGroupLabel;
// The key for record navigation and edition
// !!!!ATENTION!!!!! this field should be the primary key or
// unique value field in the table, else data can be saved in the wrong records
property KeyField: string read FKeyField write SetKeyField;
property RowNum: Integer read FRowNum write SetRowNum default 20;
end;
implementation
uses DWUtils, DWUrlHandlerRest, DWGlobal;
{ TIWBSJQGrid }
constructor TDWJQGrid.Create(AOwner: TComponent);
begin
inherited;
inherited TagType := 'table';
inherited ScriptInsideTag := False;
FColumns := TOwnedCollection.Create(Self, TDWGridColumn);
FPagination := True;
FMobileResponsive := True;
FFormatData := TFormatSettings.Create('en-US');
FSortColumn := '';
FSortOrder := bsgSortAsc;
FShowHeader := True;
FShowFooter := False;
FShowRefresh := True;
FPaginationPosition := bsgPagBottom;
FclickToSelect := True;
FSingleSelect := True;
FGroupingField := '';
FGroupSummary := False;
FGroupCollapse := False;
FGroupLabel := '';
FKeyField := '';
FRowNum := 20;
// UpdateOptions;
end;
procedure TDWJQGrid.DbJQGridCustomRestEvents0RestEvent(aParams: TStrings; var aReply: string);
function GetFieldForColumn(aColumnIndex: Integer): TField;
begin
try
Result := DataSource.DataSet.FieldByName(TDWGridColumn(FColumns.Items[aColumnIndex])
.FieldName);
except
Result := nil;
end;
end;
var
line: string;
bmrk: TBookmark;
r, i, f, t: Integer;
Lcallback: string;
Rows, Page: Integer;
begin
Lcallback := aParams.Values['callback'];
// f:=0;
// t:= DataSource.DataSet.RecordCount;
Rows := StrToIntDef(aParams.Values['rows'], FRowNum);
Page := StrToIntDef(aParams.Values['page'], 1);
f := (Page * Rows) - Rows;
t := Min(f + Rows, DataSource.DataSet.RecordCount);
DataSource.DataSet.DisableControls;
bmrk := DataSource.DataSet.Bookmark;
try
data := '';
for r := f + 1 to t do
begin
DataSource.DataSet.RecNo := r;
line := '';
for i := 0 to FColumns.Count - 1 do
begin
if i > 0 then
line := line + ',';
if (GetFieldForColumn(i) is TNumericField) then
line := line + TDWGridColumn(FColumns.Items[i]).FFieldName + ':"' +
FloatToStr(GetFieldForColumn(i).AsFloat, FFormatData) + '"'
else if (DataSource.DataSet.Fields[i] is TStringField) or
(GetFieldForColumn(i) is TMemoField) then
line := line + TDWGridColumn(FColumns.Items[i]).FFieldName + ':"' +
EscapeJsonString(GetFieldForColumn(i).AsString) + '"'
else if GetFieldForColumn(i) <> nil then
line := line + TDWGridColumn(FColumns.Items[i]).FFieldName + ':"' +
GetFieldForColumn(i).AsString + '"'
else
line := line + TDWGridColumn(FColumns.Items[i]).FFieldName + ':""';
end;
if data <> '' then
data := data + ',';
data := data + '{' + line + '}';
end;
aReply := (Lcallback + '({"records":"' + IntToStr(DataSource.DataSet.RecordCount) + '","page":'
+ IntToStr(Page) + ',"total":' + IntToStr(Ceil(DataSource.DataSet.RecordCount / Rows)) +
',"rows": [' + data + ']})');
finally
DataSource.DataSet.GotoBookmark(bmrk);
DataSource.DataSet.EnableControls;
end;
end;
destructor TDWJQGrid.Destroy;
begin
FColumns.Free;
inherited;
end;
procedure TDWJQGrid.DoEditRow(aParams: TStrings; var aReply: string);
var
KeyValue: Variant;
Value: Variant;
Field: TField;
i: Integer;
begin
if aParams.Values['oper'] = 'edit' then
begin
if FKeyField = '' then
raise Exception.Create('No KeyField set. This must be a primarykey or unique field.');
KeyValue := aParams.Values[FKeyField];
if DataSource.DataSet.FieldByName(FKeyField).Value <> KeyValue then
begin
if Not DataSource.DataSet.Locate(FKeyField, KeyValue, [loCaseInsensitive]) then
begin
DWApplication.ShowMessage('Record not found on the server');
DWApplication.CallBackResp.AddScriptToExecute
('$("#' + HTMLName + '").trigger("reloadGrid")');
end;
end;
if DataSource.DataSet.FieldByName(FKeyField).Value = KeyValue then
begin
for i := 0 to aParams.Count - 1 do
begin
if aParams.Names[i] <> 'oper' then
begin
Field := DataSource.DataSet.FieldByName(aParams.Names[i]);
Value := aParams.Values[aParams.Names[i]];
if Field <> nil then
begin
if Field.Value <> Value then
begin
if Field.DataSet.State in [dsEdit, dsInsert] then
Field.Value := Value
else
begin
Field.DataSet.Edit;
Field.Value := Value;
Field.DataSet.Post;
end;
end;
end;
end;
end;
end
else
begin
raise Exception.Create('Server not in correct record');
end;
end;
end;
procedure TDWJQGrid.DoOnRowSel(aParams: TStrings; var aReply: string);
var
Value: Variant;
begin
if FKeyField = '' then
raise Exception.Create('No KeyField set. This must be a primarykey or unique field.');
Value := aParams.Values['key'];
if Value = '' then
Exit;
case DataSource.DataSet.FieldByName(FKeyField).DataType of
ftSmallint, ftInteger, ftWord, ftLongWord, ftShortint, ftByte:
VarCast(Value, Value, varInteger);
ftLargeint, ftAutoInc:
VarCast(Value, Value, varInt64);
ftBoolean:
VarCast(Value, Value, varBoolean);
ftFloat:
VarCast(Value, Value, varDouble);
ftCurrency, ftBCD, ftOraInterval, ftExtended:
VarCast(Value, Value, varCurrency);
ftDate:
VarCast(Value, Value, varDate);
ftTime:
VarCast(Value, Value, varDate);
ftDateTime, ftOraTimeStamp, ftTimeStampOffset:
VarCast(Value, Value, varDate);
ftBytes, ftVarBytes, ftBlob, ftGraphic, ftParadoxOle, ftDBaseOle, ftTypedBinary, ftCursor,
ftADT, ftArray, ftReference, ftDataSet, ftOraBlob, ftOraClob, ftVariant, ftInterface,
ftIDispatch, ftGuid, ftTimeStamp, ftFMTBcd, // 32..37
ftConnection, ftParams, ftStream, ftObject, ftSingle:
raise Exception.Create('Invalid Key Column for Grid ' + HTMLName);
end;
if Not DataSource.DataSet.Locate(FKeyField, Value, [loCaseInsensitive]) then
begin
DWApplication.ShowMessage('Record not found on the server');
DWApplication.CallBackResp.AddScriptToExecute('$("#' + HTMLName + '").trigger("reloadGrid")');
end;
end;
function TDWJQGrid.GetColumns: TOwnedCollection;
begin
{ if not Assigned(FColumns) then
FColumns:= TOwnedCollection.Create(Self, TIwSrpJQGridColum); }
Result := FColumns;
end;
function TDWJQGrid.GetTagType: string;
begin
Result := inherited TagType;
end;
procedure TDWJQGrid.InternalRenderScript(const AHTMLName: string; AScript: TStringList);
begin
inherited;
UpdateOptions;
AScript.Add('var w = $("#{%htmlname%}").parent().width();' + 'w = w - 20;' +
'$("#{%htmlname%}").jqGrid({%options%});' +
'var lastRowSel{%htmlname%};' + 'var InEditMode{%htmlname%};' +
'function internalSelectRow(id) {' +
'var gridEditable{%htmlname%} = ($("#{%htmlname%}").getGridParam(''editurl'') !== "clientArray");'
+ 'if (id && id !== lastRowSel{%htmlname%}) {' +
'$("#{%htmlname%}").jqGrid(''saveRow'',lastRowSel{%htmlname%});' +
'if (gridEditable{%htmlname%}) {' +
'$("#{%htmlname%}").jqGrid(''editRow'',id, {keys:true, focusField: 1});' + '};' +
'lastRowSel{%htmlname%} = id;' +
// 'setTimeout(function(){' +
'InEditMode{%htmlname%} = ($($("#' + HTMLName +
'").jqGrid("getInd",lastRowSel{%htmlname%},true)).attr("editable") === ''1'') || false;' +
'executeAjaxEvent("&key="+id, null, "{%htmlname%}.DoOnRowSel", false, null, true);' +
// '}, 10);'+
'}' + '};' +
'function internalBeforeRequest(){' +
// 'var InEditMode = ($($("#' + HTMLName + '").jqGrid("getInd",lastRowSel,true)).attr("editable") === ''1'') || false;' +
'return !InEditMode{%htmlname%};' + '};'
);
DWApplication.RegisterRestCallBack(Self, AHTMLName + '.DoOnRowSel', DoOnRowSel);
end;
function TDWJQGrid.IsSortFieldNameStored: Boolean;
begin
Result := FSortColumn <> '';
end;
function TDWJQGrid.IsTagTypeStored: Boolean;
begin
Result := TagType <> 'table';
end;
function TDWJQGrid.RenderAsync: TDWElementXHTMLTag;
var
CurrDatasetPage: Integer;
begin
if FColumns.Count = 0 then
UpdateOptions;
Result := inherited;
if (DataSource <> nil) and (not(DataSource.DataSet.State in [dsEdit, dsInsert])) then
begin
CurrDatasetPage := Round((DataSource.DataSet.RecNo / FRowNum) + 0.49999);
DWApplication.CallBackResp.AddScriptToExecute('if (!InEditMode' + HTMLName + ') {' + '$("#' +
HTMLName + '").trigger("reloadGrid" ,[{page:' + IntToStr(CurrDatasetPage) + '}]);' +
'setTimeout(function(){' + '$("#' + HTMLName + '").jqGrid("resetSelection");' + '$("#' +
HTMLName + '").jqGrid("setSelection","' + DataSource.DataSet.FieldByName(FKeyField).AsString
+ '", false);' + '}, 500);' + '};');
end;
(* IWBSExecuteAsyncJScript(' var GridInEdit =
$("#' + HTMLName + '").trigger("reloadGrid")');
$($("#list").jqGrid("getInd",rowid,true)).attr("editable") === "1") {
// the row having id=rowid is in editing mode
} *)
end;
function TDWJQGrid.RenderHTML: TDWElementTag;
begin
if FColumns.Count = 0 then
UpdateOptions;
Result := inherited;
end;
procedure TDWJQGrid.VerifyColumns;
var
J: Integer;
KeyOk: Boolean;
begin
if (FColumns.Count = 0) and (Assigned(DataSource)) then
begin
for J := 0 to DataSource.DataSet.FieldCount - 1 do
begin
with TDWGridColumn(FColumns.Add) do
begin
FieldName := DataSource.DataSet.Fields[J].FieldName;
Title := DataSource.DataSet.Fields[J].DisplayName;
end;
end;
end;
KeyOk := False;
for J := 0 to FColumns.Count - 1 do
begin
if AnsiCompareText(FKeyField, TDWGridColumn(FColumns.Items[J]).FieldName) = 0 then
begin
KeyOk := True;
Break;
end;
end;
// add Key Column
if not KeyOk then
with TDWGridColumn(FColumns.Add) do
begin
FieldName := FKeyField;
Title := 'KEY';
Visible := False;
Editable := False;
end;
end;
procedure TDWJQGrid.SetclickToSelect(const Value: Boolean);
begin
if FclickToSelect <> Value then
begin
FclickToSelect := Value;
UpdateOptions;
end;
end;
procedure TDWJQGrid.SetColumns(const Value: TOwnedCollection);
begin
{ if not Assigned(FColumns) then
FColumns:= TOwnedCollection.Create(Self, TIwSrpJQGridColum); }
if Value <> FColumns then
begin
FColumns.Assign(Value);
UpdateOptions;
end;
end;
procedure TDWJQGrid.SetDataSource(const Value: TDataSource);
begin
inherited;
end;
procedure TDWJQGrid.SetGroupCollapse(const Value: Boolean);
begin
FGroupCollapse := Value;
end;
procedure TDWJQGrid.SetGroupingField(const Value: string);
begin
FGroupingField := Value;
end;
procedure TDWJQGrid.SetGroupLabel(const Value: string);
begin
FGroupLabel := Value;
end;
procedure TDWJQGrid.SetGroupSummary(const Value: Boolean);
begin
FGroupSummary := Value;
end;
procedure TDWJQGrid.SetKeyField(const Value: string);
begin
FKeyField := Value;
end;
procedure TDWJQGrid.SetMobileResponsive(const Value: Boolean);
begin
if FMobileResponsive <> Value then
begin
FMobileResponsive := Value;
UpdateOptions;
end;
end;
procedure TDWJQGrid.SetPagination(const Value: Boolean);
begin
FPagination := Value;
UpdateOptions;
end;
procedure TDWJQGrid.SetPaginationPosition(const Value: TBsJQGPagPosition);
begin
if FPaginationPosition <> Value then
begin
FPaginationPosition := Value;
UpdateOptions;
end;
end;
procedure TDWJQGrid.SetRowNum(const Value: Integer);
begin
FRowNum := Value;
end;
procedure TDWJQGrid.SetShowFooter(const Value: Boolean);
begin
if FShowFooter <> Value then
begin
FShowFooter := Value;
UpdateOptions;
end;
end;
procedure TDWJQGrid.SetShowHeader(const Value: Boolean);
begin
if FShowHeader <> Value then
begin
FShowHeader := Value;
UpdateOptions;
end;
end;
procedure TDWJQGrid.SetShowRefresh(const Value: Boolean);
begin
if FShowRefresh <> Value then
begin
FShowRefresh := Value;
UpdateOptions;
end;
end;
procedure TDWJQGrid.SetSingleSelect(const Value: Boolean);
begin
if FSingleSelect <> Value then
begin
FSingleSelect := Value;
UpdateOptions;
end;
end;
procedure TDWJQGrid.SetSortColumn(const Value: string);
begin
if FSortColumn <> Value then
begin
FSortColumn := Value;
UpdateOptions;
end;
end;
procedure TDWJQGrid.SetSortOrder(const Value: TBsJQGSortOrder);
begin
if FSortOrder <> Value then
begin
FSortOrder := Value;
UpdateOptions;
end;
end;
procedure TDWJQGrid.SetTagType(const Value: string);
begin
inherited TagType := Value;
UpdateOptions;
end;
procedure TDWJQGrid.UpdateOptions;
var
OptColumns: string;
OptColumn, OptTxt: TStrings;
J: Integer;
Field: TField;
LGridEditable: Boolean;
begin
VerifyColumns;
LGridEditable := False;
OptColumns := '';
OptColumn := TStringList.Create;
try
OptColumn.NameValueSeparator := ':';
OptColumn.Delimiter := ',';
OptColumn.QuoteChar := ' ';
OptColumn.StrictDelimiter := True;
for J := 0 to FColumns.Count - 1 do
begin
OptColumn.Clear;
with TDWGridColumn(FColumns.Items[J]) do
begin
OptColumn.Values['label'] := '''' + FTitle + '''';
OptColumn.Values['name'] := '''' + FFieldName + '''';
if AnsiUpperCase(FFieldName) = AnsiUpperCase(FKeyField) then
OptColumn.Values['key'] := 'true';
if Not FVisible then
OptColumn.Values['hidden'] := 'true';
if not FSortable then
OptColumn.Values['sortable'] := 'false';
if not FResizable then
OptColumn.Values['resizable'] := 'false';
case FHeaderAlign of
bscAlLeft:
OptColumn.Values['labelAlign'] := '"left"';
bscAlRight:
OptColumn.Values['labelAlign'] := '"right"';
bscAlDefault:
OptColumn.Values['labelAlign'] := '"likeData"';
// bscAlCenter is default
end;
case FDataAlign of
bscAlLeft:
OptColumn.Values['align'] := '"left"';
bscAlRight:
OptColumn.Values['align'] := '"right"';
bscAlCenter:
OptColumn.Values['align'] := '"center"';
end;
if FCSSclass <> '' then
OptColumn.Values['classes'] := '''' + FCSSclass + '''';
if Editable then
begin
LGridEditable := True;
if AnsiUpperCase(FKeyField) <> AnsiUpperCase(FieldName) then
OptColumn.Values['editable'] := 'true'
else
OptColumn.Values['editable'] := 'false'; // KeyField is not editable
end
else
OptColumn.Values['editable'] := 'false';
if Assigned(DataSource) and Assigned(DataSource.DataSet) then
begin
Field := DataSource.DataSet.FieldByName(FieldName);
case Field.DataType of
ftUnknown:
;
ftString:
begin
if Editable then
OptColumn.Values['edittype'] := '"text"';
end;
ftSmallint:
begin
if Editable then
OptColumn.Values['edittype'] := '"text"';
OptColumn.Values['formatter'] := '"integer"';
OptColumn.Values['align'] := '"right"';
end;
ftInteger:
begin
if Editable then
OptColumn.Values['edittype'] := '"text"';
OptColumn.Values['formatter'] := '"integer"';
OptColumn.Values['align'] := '"right"';
end;
ftWord:
begin
end;
ftBoolean:
begin
if Editable then
begin
OptColumn.Values['edittype'] := '"checkbox"';
OptColumn.Values['editoptions'] := '{value:"True:False"}';
end;
OptColumn.Values['formatter'] := '"checkbox"';
OptColumn.Values['align'] := '"center"';
end;
ftFloat:
begin
if Editable then
OptColumn.Values['edittype'] := '"text"';
OptColumn.Values['formatter'] := '"number"';
OptColumn.Values['align'] := '"right"';
end;
ftCurrency:
begin
if Editable then
OptColumn.Values['edittype'] := '"text"';
OptColumn.Values['formatter'] := '"currency"';
OptColumn.Values['align'] := '"right"';
end;
ftBCD:
begin
if Editable then
OptColumn.Values['edittype'] := '"text"';
OptColumn.Values['formatter'] := '"number"';
OptColumn.Values['align'] := '"right"';
end;
ftDate:
begin
// OptColumn.Values['formatter']:='"date"';
OptColumn.Values['align'] := '"center"';
end;
ftTime:
begin
// OptColumn.Values['formatter']:='"date"';
OptColumn.Values['align'] := '"center"';
end;
ftDateTime:
begin
// OptColumn.Values['formatter']:='"date"';
OptColumn.Values['align'] := '"center"';
end;
ftBytes:
begin
end;
ftVarBytes:
begin
end;
ftAutoInc:
begin
OptColumn.Values['formatter'] := '"integer"';
OptColumn.Values['align'] := '"right"';
end;
ftBlob:
begin
end;
ftMemo:
begin
if Editable then
OptColumn.Values['edittype'] := '"textarea"';
end;
ftGraphic:
begin
if Editable then
OptColumn.Values['edittype'] := '"textarea"';
end;
ftFmtMemo:
begin
if Editable then
OptColumn.Values['edittype'] := '"textarea"';
end;
ftParadoxOle:
begin
end;
ftDBaseOle:
begin
end;
ftTypedBinary:
begin
end;
ftCursor:
begin
end;
ftFixedChar:
begin
if Editable then
OptColumn.Values['edittype'] := '"text"';
end;
ftWideString:
begin
if Editable then
OptColumn.Values['edittype'] := '"text"';
end;
ftLargeint:
begin
if Editable then
OptColumn.Values['edittype'] := '"text"';
OptColumn.Values['formatter'] := '"integer"';
end;
ftADT:
begin
end;
ftArray:
begin
end;
ftReference:
begin
end;
ftDataSet:
begin
end;
ftOraBlob:
begin
end;
ftOraClob:
begin
end;
ftVariant:
begin
if Editable then
OptColumn.Values['edittype'] := '"textarea"';
end;
ftInterface:
begin
end;
ftIDispatch:
begin
end;
ftGuid:
begin
end;
ftTimeStamp:
begin
end;
ftFMTBcd:
begin
end;
ftFixedWideChar:
begin
if Editable then
OptColumn.Values['edittype'] := '"text"';
end;
ftWideMemo:
begin
if Editable then
OptColumn.Values['edittype'] := '"textarea"';
end;
ftOraTimeStamp:
begin
end;
ftOraInterval:
begin
end;
ftLongWord:
begin
end;
ftShortint:
begin
if Editable then
OptColumn.Values['edittype'] := '"text"';
OptColumn.Values['formatter'] := '"integer"';
OptColumn.Values['align'] := '"right"';
end;
ftByte:
begin
if Editable then
OptColumn.Values['edittype'] := '"text"';
OptColumn.Values['formatter'] := '"integer"';
OptColumn.Values['align'] := '"right"';
end;
ftExtended:
begin
if Editable then
OptColumn.Values['edittype'] := '"text"';
OptColumn.Values['formatter'] := '"number"';
OptColumn.Values['align'] := '"right"';
end;
ftConnection:
begin
end;
ftParams:
begin
if Editable then
OptColumn.Values['edittype'] := '"textarea"';
end;
ftStream:
begin
if Editable then
OptColumn.Values['edittype'] := '"text"';
end;
ftTimeStampOffset:
begin
end;
ftObject:
begin
end;
ftSingle:
begin
end;
end;
end;
(*
case FDataVertAlign of
bscAlVerTop:
OptColumns := OptColumns + '","valign":"top';
bscAlVerBottom:
OptColumns := OptColumns + '","valign":"bottom';
bscAlVerMiddle:
OptColumns := OptColumns + '","valign":"middle';
end;
case FFooterAlign of
bscAlLeft:
OptColumns := OptColumns + '","falign":"left';
bscAlRight:
OptColumns := OptColumns + '","falign":"right';
bscAlCenter:
OptColumns := OptColumns + '","falign":"center';
end; *)
if (FWidth <> '') then
OptColumn.Values['width'] := FWidth;
if OptColumns = '' then
OptColumns := '{' + OptColumn.DelimitedText + '}'
else
OptColumns := OptColumns + ',{' + OptColumn.DelimitedText + '}';
end;
end;
OptTxt := TStringList.Create;
try
OptTxt.NameValueSeparator := ':';
OptTxt.Delimiter := ',';
OptTxt.QuoteChar := ' ';
OptTxt.StrictDelimiter := True;
try
OptTxt.Values['url'] := '"' + DWApplication.RegisterRestCallBack(Self,
HTMLName + '.dataurl', DbJQGridCustomRestEvents0RestEvent) + '"';
except