Since: 1.0
Author: Kartik Visweswaran (kartikv2@gmail.com)
Inheritance: extends kartik\base\AssetBundle
Exemplo n.º 1
0
 /**
  * Registers client assets
  */
 protected function registerAssets()
 {
     $view = $this->getView();
     $script = '';
     if ($this->bootstrap) {
         GridViewAsset::register($view);
     }
     $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(['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(ArrayHelper::merge($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 = ArrayHelper::merge($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) . ");";
     }
     $script .= $this->getToggleDataScript();
     $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}();");
 }
Exemplo n.º 2
0
 /**
  * Registers client assets
  */
 protected function registerAssets()
 {
     $view = $this->getView();
     $script = '';
     if ($this->bootstrap) {
         GridViewAsset::register($view);
     }
     $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(['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(ArrayHelper::merge($rcDefaults, $this->resizableColumnsOptions));
         $contId = $this->containerOptions['id'];
         GridResizeColumnsAsset::register($view);
         $script .= "\$('#{$contId}').resizableColumns({$rcOptions});";
     }
     if ($this->floatHeader) {
         GridFloatHeadAsset::register($view);
         $this->floatHeaderOptions = ArrayHelper::merge(['floatTableClass' => 'kv-table-float', 'floatContainerClass' => 'kv-thead-float'], $this->floatHeaderOptions);
         $opts = Json::encode($this->floatHeaderOptions);
         $script .= "\$('#{$gridId} .kv-grid-table:first').floatThead({$opts});";
     }
     $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}();");
 }
Exemplo n.º 3
0
 /**
  * Register assets
  */
 protected function registerAssets()
 {
     $view = $this->getView();
     GridViewAsset::register($view);
     if ($this->export !== false && is_array($this->export) && !empty($this->export)) {
         GridExportAsset::register($view);
         $js = '';
         $popup = ArrayHelper::getValue($this->export, 'browserPopupsMsg', '');
         foreach ($this->exportConfig as $format => $setting) {
             $id = '$("#' . $this->id . ' .export-' . $format . '")';
             $grid = new JsExpression('$("#' . $this->id . '")');
             $options = ['grid' => $grid, 'filename' => $setting['filename'], 'showHeader' => $setting['showHeader'], 'showPageSummary' => $setting['showPageSummary'], 'showFooter' => $setting['showFooter'], 'worksheet' => ArrayHelper::getValue($setting, 'worksheet', ''), 'colDelimiter' => ArrayHelper::getValue($setting, 'colDelimiter', ''), 'rowDelimiter' => ArrayHelper::getValue($setting, 'rowDelimiter', ''), 'alertMsg' => ArrayHelper::getValue($setting, 'alertMsg', false), 'browserPopupsMsg' => $popup, 'cssFile' => ArrayHelper::getValue($setting, 'cssFile', '')];
             $view->registerJs($id . '.gridexport(' . Json::encode($options) . ');');
         }
     }
     if ($this->floatHeader) {
         GridFloatHeadAsset::register($view);
         $this->floatHeaderOptions = ArrayHelper::merge(['floatTableClass' => 'kv-table-float', 'floatContainerClass' => 'kv-thead-float'], $this->floatHeaderOptions);
         $js = '$("#' . $this->id . ' table").floatThead(' . Json::encode($this->floatHeaderOptions) . ');';
         $view->registerJs($js);
     }
 }