kartik\grid\GridView::registerAssets PHP Method

registerAssets() protected method

Registers client assets for the GridView widget.
protected registerAssets ( )
    protected function registerAssets()
    {
        $view = $this->getView();
        $script = '';
        if ($this->bootstrap) {
            GridViewAsset::register($view);
        }
        Dialog::widget($this->krajeeDialogSettings);
        $gridId = $this->options['id'];
        if ($this->export !== false && is_array($this->export) && !empty($this->export)) {
            GridExportAsset::register($view);
            $target = ArrayHelper::getValue($this->export, 'target', self::TARGET_POPUP);
            $gridOpts = Json::encode(['gridId' => $gridId, 'target' => $target, 'messages' => $this->export['messages'], 'exportConversions' => $this->exportConversions, 'showConfirmAlert' => ArrayHelper::getValue($this->export, 'showConfirmAlert', true)]);
            $gridOptsVar = 'kvGridExp_' . hash('crc32', $gridOpts);
            $view->registerJs("var {$gridOptsVar}={$gridOpts};", View::POS_HEAD);
            foreach ($this->exportConfig as $format => $setting) {
                $id = "\$('#{$gridId} .export-{$format}')";
                $genOpts = Json::encode(['filename' => $setting['filename'], 'showHeader' => $setting['showHeader'], 'showPageSummary' => $setting['showPageSummary'], 'showFooter' => $setting['showFooter']]);
                $genOptsVar = 'kvGridExp_' . hash('crc32', $genOpts);
                $view->registerJs("var {$genOptsVar}={$genOpts};", View::POS_HEAD);
                $expOpts = Json::encode(['dialogLib' => ArrayHelper::getValue($this->krajeeDialogSettings, 'libName', 'krajeeDialog'), 'gridOpts' => new JsExpression($gridOptsVar), 'genOpts' => new JsExpression($genOptsVar), 'alertMsg' => ArrayHelper::getValue($setting, 'alertMsg', false), 'config' => ArrayHelper::getValue($setting, 'config', [])]);
                $expOptsVar = 'kvGridExp_' . hash('crc32', $expOpts);
                $view->registerJs("var {$expOptsVar}={$expOpts};", View::POS_HEAD);
                $script .= "{$id}.gridexport({$expOptsVar});";
            }
        }
        if ($this->resizableColumns) {
            $rcDefaults = [];
            if ($this->persistResize) {
                GridResizeStoreAsset::register($view);
            } else {
                $rcDefaults = ['store' => null];
            }
            $rcOptions = Json::encode(array_replace_recursive($rcDefaults, $this->resizableColumnsOptions));
            $contId = $this->containerOptions['id'];
            GridResizeColumnsAsset::register($view);
            $script .= "\$('#{$contId}').resizableColumns('destroy').resizableColumns({$rcOptions});";
        }
        $container = "\$('#{$this->containerOptions['id']}')";
        if ($this->floatHeader) {
            GridFloatHeadAsset::register($view);
            // fix floating header for IE browser when using group grid functionality
            $skipCss = '.kv-grid-group-row,.kv-group-header,.kv-group-footer';
            // skip these CSS for IE
            $js = 'function($table){return $table.find("tbody tr:not(' . $skipCss . '):visible:first>*");}';
            $opts = ['floatTableClass' => 'kv-table-float', 'floatContainerClass' => 'kv-thead-float', 'getSizingRow' => new JsExpression($js)];
            if ($this->floatOverflowContainer) {
                $opts['scrollContainer'] = new JsExpression("function(){return {$container};}");
            }
            $this->floatHeaderOptions = array_replace_recursive($opts, $this->floatHeaderOptions);
            $opts = Json::encode($this->floatHeaderOptions);
            $script .= "\$('#{$gridId} .kv-grid-table:first').floatThead({$opts});";
        }
        if ($this->perfectScrollbar) {
            GridPerfectScrollbarAsset::register($view);
            $script .= "{$container}.perfectScrollbar(" . Json::encode($this->perfectScrollbarOptions) . ");";
        }
        $this->genToggleDataScript();
        $script .= $this->_toggleScript;
        $this->_gridClientFunc = 'kvGridInit_' . hash('crc32', $script);
        $this->options['data-krajee-grid'] = $this->_gridClientFunc;
        $view->registerJs("var {$this->_gridClientFunc}=function(){\n{$script}\n};\n{$this->_gridClientFunc}();");
    }