-
-
Notifications
You must be signed in to change notification settings - Fork 301
/
GridViewTrait.php
1992 lines (1869 loc) · 86.4 KB
/
GridViewTrait.php
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
<?php
/**
* @package yii2-grid
* @author Kartik Visweswaran <kartikv2@gmail.com>
* @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2022
* @version 3.5.1
*/
namespace kartik\grid;
use Closure;
use Exception;
use kartik\base\Config;
use kartik\base\Lib;
use kartik\dialog\Dialog;
use Yii;
use yii\base\InvalidConfigException;
use yii\grid\Column;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use yii\helpers\Inflector;
use yii\helpers\Json;
use yii\helpers\Url;
use yii\web\JsExpression;
use yii\web\Request;
use yii\widgets\Pjax;
/**
* The Krajee GridView Trait contains all methods and properties that enhances the Yii2 GridView widget.
*
* @see http://demos.krajee.com/grid
* @author Kartik Visweswaran <kartikv2@gmail.com>
* @since 1.0
*/
trait GridViewTrait
{
/**
* @var string the module identifier if this widget is part of a module. If not set, the module identifier will
* be auto derived based on the \yii\base\Module::getInstance method. This can be useful, if you are setting
* multiple module identifiers for the same module in your Yii configuration file. To specify children or grand
* children modules you can specify the module identifiers relative to the parent module (e.g. `admin/content`).
*/
public $moduleId;
/**
* @var array configuration settings for the Krajee dialog widget that will be used to render alerts and
* confirmation dialog prompts
* @see http://demos.krajee.com/dialog
*/
public $krajeeDialogSettings = [];
/**
* @var string the default label shown for each record in the grid (singular). This label will replace the singular
* word `item` within the grid summary text as well as ActionColumn default delete confirmation message.
*/
public $itemLabelSingle;
/**
* @var string the default label shown for each record in the grid (plural). This label will replace the plural word
* `items` within the grid summary text.
*/
public $itemLabelPlural;
/**
* @var string the default label shown for each record in the grid (plural). Similar to [[itemLabelPlural]] but
* this is applicable for languages like russian, where the plural label can be different for fewer item count.
* This label will replace the plural word `items-few` within the grid summary text.
*/
public $itemLabelFew;
/**
* @var string the default label shown for each record in the grid (plural). Similar to [[itemLabelPlural]] but
* this is applicable for languages like russian, where the plural label can be different for many item count.
* This label will replace the plural word `items-many` within the grid summary text.
*/
public $itemLabelMany;
/**
* @var string the default label shown for each record in the grid (accusative case). This is applicable for few
* languages like German.
*/
public $itemLabelAccusative;
/**
* @var string the template for rendering the grid within a bootstrap styled panel.
* The following special tokens are recognized and will be replaced:
* - `{prefix}`: _string_, the CSS prefix name as set in [[panelPrefix]]. Defaults to `panel panel-`.
* - `{type}`: _string_, the panel type that will append the bootstrap contextual CSS.
* - `{panelHeading}`: _string_, which will render the panel heading block.
* - `{panelBefore}`: _string_, which will render the panel before block.
* - `{panelAfter}`: _string_, which will render the panel after block.
* - `{panelFooter}`: _string_, which will render the panel footer block.
* - `{items}`: _string_, which will render the grid items.
* - `{summary}`: _string_, which will render the grid results summary.
* - `{pager}`: _string_, which will render the grid pagination links.
* - `{toolbar}`: _string_, which will render the [[toolbar]] property passed
* - `{toolbarContainer}`: _string_, which will render the toolbar container. See [[renderToolbarContainer()]].
* - `{export}`: _string_, which will render the [[export]] menu button content.
*/
public $panelTemplate = <<< HTML
{panelHeading}
{panelBefore}
{items}
{panelAfter}
{panelFooter}
HTML;
/**
* @var string the template for rendering the panel heading. The following special tokens are
* recognized and will be replaced:
* - `{title}`: _string_, which will render the panel heading title content.
* - `{summary}`: _string_, which will render the grid results summary.
* - `{items}`: _string_, which will render the grid items.
* - `{pager}`: _string_, which will render the grid pagination links.
* - `{sort}`: _string_, which will render the grid sort links.
* - `{toolbar}`: _string_, which will render the [[toolbar]] property passed
* - `{toolbarContainer}`: _string_, which will render the toolbar container. See [[renderToolbarContainer()]].
* - `{export}`: _string_, which will render the [[export]] menu button content.
*/
public $panelHeadingTemplate = <<< HTML
{summary}
{title}
<div class="clearfix"></div>
HTML;
/**
* @var string the template for rendering the panel footer. The following special tokens are
* recognized and will be replaced:
* - `{title}`: _string_, which will render the panel heading title content.
* - `{footer}`: _string_, which will render the panel footer content.
* - `{summary}`: _string_, which will render the grid results summary.
* - `{items}`: _string_, which will render the grid items.
* - `{sort}`: _string_, which will render the grid sort links.
* - `{pager}`: _string_, which will render the grid pagination links.
* - `{toolbar}`: _string_, which will render the [[toolbar]] property passed
* - `{export}`: _string_, which will render the [[export]] menu button content
*/
public $panelFooterTemplate = <<< HTML
<div class="kv-panel-pager">
{pager}
</div>
{footer}
<div class="clearfix"></div>
HTML;
/**
* @var string the template for rendering the `{before} part in the layout templates.
* The following special tokens are recognized and will be replaced:
* - `{before}`: _string_, which will render the [[before]] text passed in the panel settings
* - `{summary}`: _string_, which will render the grid results summary.
* - `{items}`: _string_, which will render the grid items.
* - `{sort}`: _string_, which will render the grid sort links.
* - `{pager}`: _string_, which will render the grid pagination links.
* - `{toolbar}`: _string_, which will render the [[toolbar]] property passed
* - `{toolbarContainer}`: _string_, which will render the toolbar container. See [[renderToolbarContainer()]].
* - `{export}`: _string_, which will render the [[export]] menu button content
*/
public $panelBeforeTemplate = <<< HTML
{toolbarContainer}
{before}
<div class="clearfix"></div>
HTML;
/**
* @var string the template for rendering the `{after} part in the layout templates. The following special
* variables are recognized and will be replaced:
* - `{after}`: _string_, which will render the `after` text passed within the [[panel]] settings
* - `{summary}`: _string_, which will render the grid results summary.
* - `{items}`: _string_, which will render the grid items.
* - `{sort}`: _string_, which will render the grid sort links.
* - `{pager}`: _string_, which will render the grid pagination links.
* - `{toolbar}`: _string_, which will render the [[toolbar]] property passed
* - `{toolbarContainer}`: _string_, which will render the toolbar container. See [[renderToolbarContainer()]].
* - `{export}`: _string_, which will render the [[export]] menu button content
*/
public $panelAfterTemplate = '{after}';
/**
* @var string the panel CSS prefix that will be applied to the panel container for rendering the grid
* within a bootstrap styled panel. This can be set to a different value to generate different styles for
* other bootstrap themes. For example, this can be set to `box box-` for rendering boxes in AdminLTE theme.
*/
public $panelPrefix;
/**
* @var array the panel settings for displaying the grid view within a bootstrap styled panel. This property is
* therefore applicable only if [[bootstrap]] property is `true`. The following array keys can be configured:
* - `type`: _string_, the panel contextual type. Set it to one of the TYPE constants. If not set, will default to
* [[TYPE_DEFAULT]].
* - `options`: _array_, the HTML attributes for the panel container. If the `class` is not set, it will be auto
* derived using the panel `type` and [[panelPrefix]]
* - `heading`: `string`|`boolean`, the panel heading. If set to `false`, will not be displayed.
* - `headingOptions`: _array_, HTML attributes for the panel heading container. Defaults to:
* - `['class'=>'panel-heading']` when [[bsVersion]] = `3.x`, and
* - `['class'=>'card-heading <COLOR>']` when [[bsVersion]] = `4.x` - the color will be auto calculated based on
* the `type` setting
* - `titleOptions`: _array_, HTML attributes for the panel title container. The following tags are specially
* parsed:
* - `tag`: _string_, the HTML tag to render the title. Defaults to `h3` when [[bsVersion]] = `3.x` and `span`
* when [[bsVersion]] = `4.x`
* The `titleOptions` defaults to:
* - `['class'=>'panel-title']` when [[bsVersion]] = `3.x`, and
* - `[]` when [[bsVersion]] = `4.x`
* - `summaryOptions`: _array_, HTML attributes for the panel summary section container. Defaults to:
* - `['class'=>'pull-right']` when [[bsVersion]] = `3.x`, and
* - `['class'=>'float-right']` when [[bsVersion]] = `4.x`, and
* - `footer`: `string`|`boolean`, the panel footer. If set to `false` will not be displayed.
* - `footerOptions`: _array_, HTML attributes for the panel footer container. Defaults to:
* - `['class'=>'panel-footer']` when [[bsVersion]] = `3.x`, and
* - `['class'=>'card-footer']` when [[bsVersion]] = `4.x`
* - 'before': `string`|`boolean`, content to be placed before/above the grid (after the header). To not display
* this section, set this to `false`.
* - `beforeOptions`: _array_, HTML attributes for the `before` text. If the `class` is not set, it will default to
* `kv-panel-before`.
* - 'after': `string`|`boolean`, any content to be placed after/below the grid (before the footer). To not
* display this section, set this to `false`.
* - `afterOptions`: _array_, HTML attributes for the `after` text. If the `class` is not set, it will default to
* `kv-panel-after`.
*/
public $panel = [];
/**
* @var array|string configuration of additional header table rows that will be rendered before the default grid
* header row. If set as a _string_, it will be displayed as is, without any HTML encoding. If set as an _array_,
* each row in this array corresponds to a HTML table row, where you can configure the columns with these properties:
* - `columns`: _array_, the header row columns configuration where you can set the following properties:
* - `content`: _string_, the grid cell content for the column
* - `tag`: _string_, the tag for rendering the grid cell. If not set, defaults to `th`.
* - `options`: _array_, the HTML attributes for the grid cell
* - `options`: _array_, the HTML attributes for the table row
*/
public $beforeHeader = [];
/**
* @var array|string configuration of additional header table rows that will be rendered after default grid header
* row. If set as a _string_, it will be displayed as is, without any HTML encoding. If set as an _array_, each
* row in this array corresponds to a HTML table row, where you can configure the columns with these properties:
* - `columns`: _array_, the header row columns configuration where you can set the following properties:
* - `content`: _string_, the grid cell content for the column
* - `tag`: _string_, the tag for rendering the grid cell. If not set, defaults to `th`.
* - `options`: _array_, the HTML attributes for the grid cell
* - `options`: _array_, the HTML attributes for the table row
*/
public $afterHeader = [];
/**
* @var array|string configuration of additional footer table rows that will be rendered before the default grid
* footer row. If set as a _string_, it will be displayed as is, without any HTML encoding. If set as an _array_,
* each row in this array corresponds to a HTML table row, where you can configure the columns with these properties:
* - `columns`: _array_, the footer row columns configuration where you can set the following properties:
* - `content`: _string_, the grid cell content for the column
* - `tag`: _string_, the tag for rendering the grid cell. If not set, defaults to `th`.
* - `options`: _array_, the HTML attributes for the grid cell
* - `options`: _array_, the HTML attributes for the table row
*/
public $beforeFooter = [];
/**
* @var array|string configuration of additional footer table rows that will be rendered after the default grid
* footer row. If set as a _string_, it will be displayed as is, without any HTML encoding. If set as an _array_,
* each row in this array corresponds to a HTML table row, where you can configure the columns with these properties:
* - `columns`: _array_, the footer row columns configuration where you can set the following properties:
* - `content`: _string_, the grid cell content for the column
* - `tag`: _string_, the tag for rendering the grid cell. If not set, defaults to `th`.
* - `options`: _array_, the HTML attributes for the grid cell
* - `options`: _array_, the HTML attributes for the table row
*/
public $afterFooter = [];
/**
* @var array|string the toolbar content configuration. Can be setup as a string or an array. When set as a
* _string_, it will be rendered as is. When set as an _array_, each line item will be considered as per the
* following rules:
* - if the line item is setup as a _string_, it will be rendered as is
* - if the line item is an _array_, the following keys can be setup to control the rendering of the toolbar:
* - `content`: _string_, the content to be rendered as a bootstrap button group. The following special tags
* in the content are recognized and will be replaced:
* - `{export}`, _string_ which will render the [[export]] menu button content.
* - `{toggleData}`, _string_ which will render the button to toggle between page data and all data.
* - `options`: _array_, the HTML attributes for the button group div container. By default the CSS class
* `btn-group` will be attached to this container if no class is set.
*/
public $toolbar = [
'{toggleData}',
'{export}',
];
/**
* @var array the HTML attributes for the toolbar container. The following special attributes are recognized:
*
* - `tag`: _string_, the HTML tag to render the toolbar container. Defaults to `div`.
*/
public $toolbarContainerOptions = ['class' => 'btn-toolbar kv-grid-toolbar toolbar-container'];
/**
* @var array tags to replace in the rendered layout. Enter this as `$key => $value` pairs, where:
* - `$key`: _string_, defines the flag.
* - `$value`: _string_|_Closure_, the value that will be replaced. You can set it as a callback function to return
* a string of the signature: `function ($widget) { return 'custom'; }`.
*
* For example, a custom tag like `{star}` can be set as:
*
* ```php
* [
* '{star}' => '<span class="glyphicon glyphicon-asterisk"></span>'
* ]
* ```
*/
public $replaceTags = [];
/**
* @var boolean whether the grid view will be rendered within a pjax container. Defaults to `false`. If set to
* `true`, the entire GridView widget will be parsed via Pjax and auto-rendered inside a yii\widgets\Pjax
* widget container. If set to `false` pjax will be disabled and none of the pjax settings will be applied.
*/
public $pjax = false;
/**
* @var array the pjax settings for the widget. This will be considered only when [[pjax]] is set to true. The
* following settings are recognized:
* - `neverTimeout`: `boolean`, whether the pjax request should never timeout. Defaults to `true`. The pjax:timeout
* event will be configured to disable timing out of pjax requests for the pjax container.
* - `options`: _array_, the options for the [[\yii\widgets\Pjax]] widget.
* - `loadingCssClass`: boolean/string, the CSS class to be applied to the grid when loading via pjax. If set to
* `false` - no css class will be applied. If it is empty, null, or set to `true`, will default to
* `kv-grid-loading`.
* - `beforeGrid`: _string_, any content to be embedded within pjax container before the Grid widget.
* - `afterGrid`: _string_, any content to be embedded within pjax container after the Grid widget.
*/
public $pjaxSettings = [];
/**
* @var bool whether to enable focused edited row feature
*/
public $enableEditedRow = false;
/**
* @var array the configuration for the row being currently edited
*/
public $editedRowConfig = [
'rowIdGetParam' => 'row',
'gridIdGetParam' => 'grid',
'gridFiltersSessionParam' => 'kvGridFiltersCache',
'highlightClass' => 'kv-row-edit-highlight',
];
/**
* @var boolean whether to allow resizing of columns
*/
public $resizableColumns = true;
/**
* @var boolean whether to hide resizable columns for smaller screen sizes (< 768px). Defaults to `true`.
*/
public $hideResizeMobile = true;
/**
* @var array the resizableColumns plugin options
*/
public $resizableColumnsOptions = ['resizeFromBody' => false];
/**
* @var boolean whether to store resized column state using local storage persistence (supported by most modern
* browsers).
*/
public $persistResize = false;
/**
* @var string resizable unique storage prefix to append to the grid id. If empty or not set it will default to
* `Yii::$app->user->id`.
*/
public $resizeStorageKey;
/**
* @var boolean whether the grid view will have Bootstrap table styling.
*/
public $bootstrap = true;
/**
* @var boolean whether the grid will have a `bordered` style. Applicable only if `bootstrap` is `true`.
*/
public $bordered = true;
/**
* @var boolean whether the grid will have a `striped` style. Applicable only if `bootstrap` is `true`.
*/
public $striped = true;
/**
* @var boolean whether the grid will have a `condensed` style. Applicable only if `bootstrap` is `true`.
*/
public $condensed = false;
/**
* @var boolean whether the grid will have a `responsive` style. Applicable only if `bootstrap` is `true`.
* Note that if you set this to `true` and `floatHeader` or `floatFooter` or `floatPageSummary` is also
* enabled to `true` - then for effective behavior set a fixed height for the container in `containerOptions`
* or add the built in class `kv-grid-wrapper` to the `containerOptions` - for example:
* ```
* 'containerOptions' => ['class' => 'kv-grid-wrapper']
* ```
*/
public $responsive = true;
/**
* @var boolean whether the grid will automatically wrap to fit columns for smaller display sizes.
*/
public $responsiveWrap = true;
/**
* @var boolean whether the grid will highlight row on `hover`. Applicable only if `bootstrap` is `true`.
*/
public $hover = false;
/**
* @var boolean whether the grid will have a floating table header. Note that the table header will stick to the
* top of the page by default if this is set to `true`. To add an offset - you can configure the CSS style
* within `headerContainer` - for example:
*
* ```
* 'headerContainer' => ['class' => 'kv-table-header, 'style' => 'top: 50px'] // to set an offset
* ```
*/
public $floatHeader = false;
/**
* @var boolean whether the grid will have a floating table footer.
*/
public $floatFooter = false;
/**
* @var boolean whether the grid table will have a floating page summary at the bottom or top depending on
* `pageSummaryPosition`. Defaults to `false`. Note that this property also automatically overrides and disables
* the `floatHeader` or `floatFooter` properties. This is because only one sticky container can exist at the top
* or bottom. Note:
* - when `pageSummaryPosition` is set to `GridView::POS_BOTTOM`, the page summary sticks to the bottom of the page,
* and overrides the `floatFooter` setting to `false`.
* - when `pageSummaryPosition` is set to `GridView::POS_TOP`, the page summary sticks to the top of the page,
* and overrides the `floatHeader` setting to `false`.
* Note that, like header or footer, you can control the positioning or offset of the page summary container via
* `pageSummaryContainer`.
*
* ```
* 'pageSummaryContainer' => ['style' => 'top: 50px'] // to set an offset
* ```
*/
public $floatPageSummary = false;
/**
* @var array the HTML options for the table `thead`. The CSS class 'kv-table-header' is added by default and
* creates the Krajee default header styling for a better float header behavior. In case you are overriding this
* property at runtime, either use your own CSS class/ style or add the default CSS 'kv-table-header'. Note that
* with `floatHeader` enabled to `true`, you may need to add an offset for the floated header from top when
* scrolling (e.g. in cases where you have a fixed bootstrap navbar on top). For example:
*
* ```
* 'headerContainer' => ['class' => 'kv-table-header, 'style' => 'top: 50px'] // to set an offset
* ```
*/
public $headerContainer = ['class' => 'kv-table-header'];
/**
* @var array the HTML options for the table <code>tfoot</code> container. The CSS class 'kv-table-footer' is added
* by default, and creates the Krajee default footer styling for a better float footer behavior. In case you are
* overriding this property at runtime, either use your own CSS class/ style or add the default CSS
* 'kv-table-footer' for maintaining a consistent sticky styling. Similar, to `headerContainer`, you can control
* other styling, like offsets. For example:
*
* ```
* 'footerContainer' => ['class' => 'kv-table-footer, 'style' => 'bottom: 50px'] // to set an offset from bottom
* ```
*/
public $footerContainer = ['class' => 'kv-table-footer'];
/**
* @deprecated since release v3.5.1
*/
public $floatOverflowContainer = false;
/**
* @deprecated since release v3.5.1
*/
public $floatHeaderOptions = [];
/**
* @var boolean whether pretty perfect scrollbars using perfect scrollbar plugin is to be used. Defaults to
* `false`.
*
* @see https://github.com/utatti/perfect-scrollbar
*/
public $perfectScrollbar = false;
/**
* @var array the plugin options for the perfect scrollbar plugin.
* @see https://github.com/noraesae/perfect-scrollbar
*/
public $perfectScrollbarOptions = [];
/**
* @var boolean whether to show the page summary row for the table. This will be displayed above the footer.
*/
public $showPageSummary = false;
/**
* @var string location of the page summary row (whether [[POS_TOP]] or [[POS_BOTTOM]])
*/
public $pageSummaryPosition = self::POS_BOTTOM;
/**
* @array the HTML attributes for the page summary container. The following special options are recognized:
*
* - `tag`: _string_, the tag used to render the page summary. Defaults to `tbody`.
*/
public $pageSummaryContainer = ['class' => 'kv-page-summary-container'];
/**
* @array the HTML attributes for the summary row.
*/
public $pageSummaryRowOptions = [];
/**
* @var string the default pagination that will be read by toggle data. Should be one of 'page' or 'all'. If not
* set to 'all', it will always defaults to 'page'.
*/
public $defaultPagination = 'page';
/**
* @var boolean whether to enable toggling of grid data. Defaults to `true`.
*/
public $toggleData = true;
/**
* @var array the settings for the toggle data button for the toggle data type. This will be setup as an
* associative array of $key => $value pairs, where $key can be:
* - `maxCount`: `int`|`boolean`, the maximum number of records uptil which the toggle button will be rendered. If
* the dataProvider records exceed this setting, the toggleButton will not be displayed. Defaults to `10000` if
* not set. If you set this to `true`, the toggle button will always be displayed. If you set this to `false
* the toggle button will not be displayed (similar to `toggleData` setting).
* - `minCount`: `int`|`boolean`, the minimum number of records beyond which a confirmation message will be
* displayed when toggling all records. If the dataProvider record count exceeds this setting, a confirmation
* message will be alerted to the user. Defaults to `500` if not set. If you set this to `true`, the
* confirmation message will always be displayed. If set to `false` no confirmation message will be displayed.
* - `confirmMsg`: _string_, the confirmation message for the toggle data when `minCount` threshold is exceeded.
* Defaults to `'There are {totalCount} records. Are you sure you want to display them all?'`.
* - `all`: _array_, configuration for showing all grid data and the value is the HTML attributes for the button.
* (refer `page` for understanding the default options).
* - `page`: _array_, configuration for showing first page data and $options is the HTML attributes for the button.
* The following special options are recognized:
* - `icon`: _string_, the glyphicon suffix name. If not set or empty will not be displayed.
* - `label`: _string_, the label for the button.
*
* This defaults to the following setting:
*
* ```php
* [
* 'maxCount' => 10000,
* 'minCount' => 1000
* 'confirmMsg' => Yii::t(
* 'kvgrid',
* 'There are {totalCount} records. Are you sure you want to display them all?',
* ['totalCount' => number_format($this->dataProvider->getTotalCount())]
* ),
* 'all' => [
* 'icon' => 'resize-full',
* 'label' => 'All',
* 'class' => 'btn btn-default', // 'btn btn-secondary' for BS4.x / BS5.x
* 'title' => 'Show all data'
* ],
* 'page' => [
* 'icon' => 'resize-small',
* 'label' => 'Page',
* 'class' => 'btn btn-default', // 'btn btn-secondary' for BS4.x / BS5.x
* 'title' => 'Show first page data'
* ],
* ]
* ```
*/
public $toggleDataOptions = [];
/**
* @var array the HTML attributes for the toggle data button group container. By default this will always have the
* `class = btn-group` automatically added, if no class is set.
*/
public $toggleDataContainer = [];
/**
* @var array the HTML attributes for the export button group container. By default this will always have the
* `class = btn-group` automatically added, if no class is set.
*/
public $exportContainer = [];
/**
* @var array|boolean the grid export menu settings. Displays a Bootstrap dropdown menu that allows you to export the
* grid as either html, csv, or excel. If set to `false`, will not be displayed. The following options can be
* set:
* - `icon`: _string_,the glyphicon suffix to be displayed before the export menu label. If not set or is an empty
* string, this will not be displayed. Defaults to `export` if `fontAwesome` is `false` and `share-square-o` if
* fontAwesome is `true`.
* - `label`: _string_,the export menu label (this is not HTML encoded). Defaults to ''.
* - `showConfirmAlert`: bool, whether to show a confirmation alert dialog before download. This confirmation
* dialog will notify user about the type of exported file for download and to disable popup blockers.
* Defaults to `true`.
* - `target`: _string_, the target for submitting the export form, which will trigger
* the download of the exported file. Must be one of the `TARGET_` constants.
* Defaults to `GridView::TARGET_POPUP`.
* - `messages`: _array_, the configuration of various messages that will be displayed at runtime:
* - `allowPopups`: _string_, the message to be shown to disable browser popups for download.
* Defaults to `Disable any popup blockers in your browser to ensure proper download.`.
* - `confirmDownload`: _string_, the message to be shown for confirming to proceed with the download. Defaults
* to `Ok to proceed?`.
* - `downloadProgress`: _string_, the message to be shown in a popup dialog when download request is
* triggered. Defaults to `Generating file. Please wait...`.
* - `downloadComplete`: _string_, the message to be shown in a popup dialog when download request is completed.
* Defaults to `All done! Click anywhere here to close this window, once you have downloaded the file.`.
* - `header`: _string_, the header for the page data export dropdown. If set to empty string will not be
* displayed. Defaults to: `<li role="presentation" class="dropdown-header">Export Page Data</li>`.
* - `fontAwesome`: bool, whether to use font awesome file type icons. Defaults to `false`. If you set it to
* `true`, then font awesome icons css class will be applied instead of glyphicons.
* - `itemsBefore`: _array_, any additional items that will be merged/prepended before with the export dropdown
* list. This should be similar to the `items` property as supported by `\yii\bootstrap\ButtonDropdown` widget.
* Note the page export items will be automatically generated based on settings in the `exportConfig` property.
* - `itemsAfter`: _array_, any additional items that will be merged/appended after with the export dropdown list.
* This should be similar to the `items` property as supported by `\yii\bootstrap\ButtonDropdown` widget. Note
* the page export items will be automatically generated based on settings in the `exportConfig` property.
* - `options`: _array_, HTML attributes for the export menu button. Defaults to
* - `['class' => 'btn btn-default']` for [[bsVersion]] = '3.x' or .
* - `['class' => 'btn btn-secondary']` for [[bsVersion]] = '4.x' / '5.x'
* - `encoding`: _string_, the export output file encoding. If not set, defaults to `utf-8`.
* - `bom`: `boolean`, whether a BOM is to be embedded for text or CSV files with utf-8 encoding. Defaults to
* `true`.
* - `menuOptions`: _array_, HTML attributes for the export dropdown menu. Defaults to `['class' => 'dropdown-menu
* dropdown-menu-right']`. This property is to be setup exactly as the `options` property required by the
* [[\yii\bootstrap\Dropdown]] widget.
* - `skipExportElements`: _array_, the list of jQuery element selectors that will be skipped and removed from
* export. Defaults to `['.sr-only', '.hide']`.
*/
public $export = [];
/**
* @var array the configuration for each export format. The array keys must be the one of the `format` constants
* (CSV, HTML, TEXT, EXCEL, PDF, JSON) and the array value is a configuration array consisiting of these settings:
* - `label`: _string_,the label for the export format menu item displayed
* - `icon`: _string_,the glyphicon or font-awesome name suffix to be displayed before the export menu item label.
* If set to an empty string, this will not be displayed. Refer `defaultConfig` in `initExport` method for
* default settings.
* - `showHeader`: `boolean`, whether to show table header row in the output. Defaults to `true`.
* - `showPageSummary`: `boolean`, whether to show table page summary row in the output. Defaults to `true`.
* - `showFooter`: `boolean`, whether to show table footer row in the output. Defaults to `true`.
* - `showCaption`: `boolean`, whether to show table caption in the output (only for HTML). Defaults to `true`.
* - `filename`: the base file name for the generated file. Defaults to 'grid-export'. This will be used to
* generate a default file name for downloading (extension will be one of csv, html, or xls - `based on the
* format setting).
* - `alertMsg`: _string_, the message prompt to show before saving. If this is empty or not set it will not be
* displayed.
* - `options`: _array_, HTML attributes for the export format menu item.
* - `mime`: _string_, the mime type (for the file format) to be set before downloading.
* - `config`: _array_, the special configuration settings specific to each file format/type. The following
* configuration options are read specific to each file type:
* - `HTML`: The following properties can be set as array key-value pairs:
* - `cssFile`: _string_, the css file that will be used in the exported HTML file. Defaults to:
* `https://maxcdn.bootstrapcdn.com/bootstrap/3.5.1/css/bootstrap.min.css`.
* - `CSV` and `TEXT`: The following properties can be set as array key-value pairs:
* - `colDelimiter`: _string_, the column delimiter string for TEXT and CSV downloads.
* - `rowDelimiter`: _string_, the row delimiter string for TEXT and CSV downloads.
* - `EXCEL`: The following properties can be set as array key-value pairs:
* - `worksheet`: _string_, the name of the worksheet, when saved as EXCEL file.
* - `PDF`: Supports all configuration properties as required in [[\kartik\mpdf\Pdf]] extension. In addition, the
* following additional special options are recognized:
* - `contentBefore`: _string_, any HTML formatted content that will be embedded in the PDF output before
* the grid.
* - `contentAfter`: _string_, any HTML formatted content that will be embedded in the PDF output after
* the grid.
* - `JSON`: The following properties can be set as array key-value pairs:
* - `colHeads`: _array_, the column heading names to be output in the json file. If not set, it will be
* autogenerated as "col-{i}", where {i} is the column index. If `slugColHeads` is set to `true`, the
* extension will attempt to autogenerate column heads based on table column heading, whereever
* possible.
* - `slugColHeads`: `boolean`, whether to auto-generate column identifiers as slugs based on the table
* column heading name. If the table column heading contains characters which cannot be slugified, then
* the extension will autogenerate the column name as "col-{i}".
* - `jsonReplacer``: array|JsExpression, the JSON replacer property - `can be an array or a JS function
* created using JsExpression. Refer the [JSON documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_native_JSON#The_replacer_parameter)
* for details on setting this property.
* - `indentSpace`: int, pretty print json output and indent by number of spaces specified. Defaults to `4`.
*/
public $exportConfig = [];
/**
* @var array conversion of defined patterns in the grid cells as a preprocessing before the gridview is formatted
* for export. Each array row must consist of the following two keys:
* - `from`: _string_, is the pattern to search for in each grid column's cells
* - `to`: _string_, is the string to replace the pattern in the grid column cells
* This defaults to:
* ```php
* [
* ['from'=>GridView::ICON_ACTIVE, 'to'=>Yii::t('kvgrid', 'Active')],
* ['from'=>GridView::ICON_INACTIVE, 'to'=>Yii::t('kvgrid', 'Inactive')]
* ]
* ```
*/
public $exportConversions = [];
/**
* @var boolean determines whether the exported EXCEL cell data will be automatically guessed and formatted based on
* [[DataColumn::format]] property. This property is applicable for EXCEL export content only. One can override this
* behavior and change the auto-derived format mask by setting [[DataColumn::xlFormat]].
*/
public $autoXlFormat = false;
/**
* @var array|boolean the HTML attributes for the grid container. The grid items will be wrapped in a `div`
* container with the configured HTML attributes. The ID for the container will be auto generated.
*/
public $containerOptions = [];
/**
* Whether to hash export config and prevent data tampering of the export config when transmitting this between
* client and server during grid data export. Defaults to `true`. You may set this to `false` if your config
* contains dynamic data (like current date time). However, note that when `false` it adds the possibility of
* your client data being tampered during grid export when read by server.
*/
public $hashExportConfig = true;
/**
* @var array the configuration for sorter icons. The array key must have an `SORT_ASC` and `SORT_DESC` entry.
* The `sorterIcons` property defaults to following if not overridden:
*
* For Bootstrap v4.x and v5.x:
* [
* SORT_ASC => '<i class="fas fa-sort-amount-down-alt"></i>',
* SORT_DESC => '<i class="fas fa-sort-amount-up"></i>'
* ]
*
* For Bootstrap v3.x:
* [
* SORT_ASC => '<i class="glyphicon glyphicon-sort-by-attributes"></i>',
* SORT_DESC => '<i class="glyphicon glyphicon-sort-by-attributes-alt"></i>',
* ]
*/
public $sorterIcons = [];
/**
* @var string the generated client script for the grid
*/
protected $_gridClientFunc = '';
/**
* @var Module the grid module.
*/
protected $_module;
/**
* @var string key to identify showing all data
*/
protected $_toggleDataKey;
/**
* @var string HTML attribute identifier for the toggle button
*/
protected $_toggleButtonId;
/**
* @var string the JS variable to store the toggle options
*/
protected $_toggleOptionsVar;
/**
* @var string generated plugin script for the toggle button
*/
protected $_toggleScript;
/**
* @var boolean whether the current mode is showing all data
*/
protected $_isShowAll = false;
/**
* @var string|null the filter cache
*/
protected $_filterCache = null;
/**
* Initializes the Krajee GridView widget
*
* @throws InvalidConfigException
*/
protected function initGridView()
{
$this->initModule();
if (isset($this->_module->bsVersion)) {
$this->bsVersion = $this->_module->bsVersion;
}
$this->initBsVersion();
$bsVer = $this->getBsVer();
$notBs3 = $bsVer > 3;
Html::addCssClass($this->options, 'is-bs'.($notBs3 ? '4' : '3'));
$this->sorterIcons += static::getDefaultSorterIcons($notBs3);
$this->initPjaxContainerId();
if (!isset($this->itemLabelSingle)) {
$this->itemLabelSingle = Yii::t('kvgrid', 'item');
}
if (!isset($this->itemLabelPlural)) {
$this->itemLabelPlural = Yii::t('kvgrid', 'items');
}
if (!isset($this->itemLabelFew)) {
$this->itemLabelFew = Yii::t('kvgrid', 'items-few');
}
if (!isset($this->itemLabelMany)) {
$this->itemLabelMany = Yii::t('kvgrid', 'items-many');
}
if (!isset($this->itemLabelAccusative)) {
$this->itemLabelAccusative = Yii::t('kvgrid', 'items-acc');
}
if ($notBs3) {
Html::addCssClass($this->options, 'kv-grid-bs4');
$this->setPagerOptionClass('linkContainerOptions', 'page-item');
$this->setPagerOptionClass('linkOptions', 'page-link');
$this->setPagerOptionClass('disabledListItemSubTagOptions', 'page-link');
} else {
Html::addCssClass($this->options, 'kv-grid-bs3');
}
if (empty($this->sorter['class'])) {
$this->sorter['class'] = GridLinkSorter::class;
$this->sorter['sorterIcons'] = $this->sorterIcons;
}
if (!$this->toggleData) {
return;
}
$this->_toggleDataKey = '_tog'.hash('crc32', $this->options['id']);
/**
* @var Request $request
*/
$request = $this->_module->get('request', false);
if ($request === null || !($request instanceof Request)) {
$request = Yii::$app->request;
}
$this->_isShowAll = $request->getQueryParam($this->_toggleDataKey, $this->defaultPagination) === 'all';
if ($this->_isShowAll) {
$this->dataProvider->pagination = false;
}
$this->_toggleButtonId = $this->options['id'].'-togdata-'.($this->_isShowAll ? 'all' : 'page');
}
/**
* Prepares the Krajee GridView widget for run
*
* @throws InvalidConfigException
*/
protected function prepareGridView()
{
$this->initToggleData();
$this->initExport();
if ($this->export !== false && isset($this->exportConfig[self::PDF])) {
Config::checkDependency(
'mpdf\Pdf',
'yii2-mpdf',
'for PDF export functionality. To include PDF export, follow the install steps below. If you do not '.
"need PDF export functionality, do not include 'PDF' as a format in the 'export' property. You can ".
"otherwise set 'export' to 'false' to disable all export functionality"
);
}
$this->initBootstrapStyle();
$this->containerOptions['id'] = $this->options['id'].'-container';
Html::addCssClass($this->containerOptions, 'kv-grid-container');
$this->initPanel();
$this->initLayout();
$this->registerAssets();
}
/**
* Gets default sorter icons
*
* @param bool $notBs3
*
* @return array
*/
public static function getDefaultSorterIcons($notBs3)
{
if ($notBs3) {
return [
SORT_ASC => '<i class="fas fa-sort-amount-down-alt"></i>',
SORT_DESC => '<i class="fas fa-sort-amount-up"></i>',
];
}
return [
SORT_ASC => '<i class="glyphicon glyphicon-sort-by-attributes"></i>',
SORT_DESC => '<i class="glyphicon glyphicon-sort-by-attributes-alt"></i>',
];
}
/**
* Parses export configuration and returns the merged defaults.
*
* @param array $exportConfig the export configuration
* @param array $defaultExportConfig the default export configuration
*
* @return array
*/
protected static function parseExportConfig($exportConfig, $defaultExportConfig)
{
if (is_array($exportConfig) && !empty($exportConfig)) {
foreach ($exportConfig as $format => $setting) {
$setup = is_array($setting) ? $setting : [];
$exportConfig[$format] = empty($setup) ? $defaultExportConfig[$format] :
array_replace_recursive($defaultExportConfig[$format], $setup);
}
return $exportConfig;
}
return $defaultExportConfig;
}
/**
* Sets a default css class within `options` if not set
*
* @param array $options the HTML options
* @param string|array $css the CSS class to test and append
*/
protected static function initCss(&$options, $css)
{
if (!isset($options['class'])) {
$options['class'] = $css;
}
}
/**
* Get pjax container identifier
*
* @return string
*/
public function getPjaxContainerId()
{
$this->initPjaxContainerId();
return $this->pjaxSettings['options']['id'];
}
/**
* Initializes pjax container identifier
*/
public function initPjaxContainerId()
{
if (empty($this->options['id'])) {
$this->options['id'] = $this->getId();
}
if (empty($this->pjaxSettings['options']['id'])) {
$this->pjaxSettings['options']['id'] = $this->options['id'].'-pjax';
}
}
/**
* @return array|false
*/
protected function initEditedRow()
{
if (!$this->enableEditedRow) {
return false;
}
$cfg = $this->editedRowConfig;
$session = Yii::$app->session;
$request = Yii::$app->request;
$row = !isset($cfg['rowIdGetParam']) ? null : $request->get($cfg['rowIdGetParam']);
$grid = !isset($cfg['gridIdGetParam']) ? null : $request->get($cfg['gridIdGetParam'], $this->options['id']);
if (!empty($session) && !empty($cfg['gridFiltersSessionParam'])) {
$filter = $cfg['gridFiltersSessionParam'];
$queryParams = $request->queryParams;
unset($queryParams[$cfg['rowIdGetParam']], $queryParams[$cfg['gridIdGetParam']]);
$session->set($filter, Json::encode($queryParams));
}
return ['row' => $row, 'grid' => $grid, 'css' => $cfg['highlightClass']];
}
/**
* Adds CSS class to the pager parameter
*
* @param string $param the pager param
* @param string $css the CSS class
*
* @throws Exception
*/
protected function setPagerOptionClass($param, $css)
{
$opts = ArrayHelper::getValue($this->pager, $param, []);
Html::addCssClass($opts, $css);
$this->pager[$param] = $opts;
}
/**
* Renders the table page summary.
*
* @return string the rendering result.
* @throws Exception
*/
public function renderPageSummary()
{
if (!$this->showPageSummary) {