Skip to content

Commit

Permalink
Fix #407: Enhance data-key generation
Browse files Browse the repository at this point in the history
  • Loading branch information
kartik-v committed Aug 26, 2019
1 parent 06b4ddf commit bfb16b4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Change Log: `yii2-grid`
**Date:** _under development_

- (bug #924): Correct `rowOptions` init.
- (bug #407): Enhance `data-key` generation.

## Version 3.3.3

Expand Down
3 changes: 1 addition & 2 deletions src/ExpandRowColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,7 @@ public function getDataCellValue($model, $key, $index)
Html::addCssClass($detailOptions, 'skip-export');
}
$detailOptions['data-index'] = $index;
$detailOptions['data-key'] = !is_string($key) && !is_numeric($key) ?
(is_array($key) ? Json::encode($key) : (string)$key) : $key;
$detailOptions['data-key'] = GridView::parseKey($key);
Html::addCssClass($detailOptions, ['kv-expanded-row', $this->_colId]);
$content = Html::tag('div', $detail, $detailOptions);
return <<< HTML
Expand Down
21 changes: 16 additions & 5 deletions src/GridView.php
Original file line number Diff line number Diff line change
Expand Up @@ -1254,7 +1254,7 @@ protected function getPageSummaryRow()
}
$cells[] = $column->renderPageSummaryCell();
if (!empty($column->pageSummaryOptions['colspan'])) {
$span = (int) $column->pageSummaryOptions['colspan'];
$span = (int)$column->pageSummaryOptions['colspan'];
$dir = ArrayHelper::getValue($column->pageSummaryOptions, 'data-colspan-dir', 'ltr');
if ($span > 0) {
$fm = ($dir === 'ltr') ? ($i + 1) : ($i - $span + 1);
Expand All @@ -1265,7 +1265,7 @@ protected function getPageSummaryRow()
}
}
}
if (!empty($skipped )) {
if (!empty($skipped)) {
for ($i = 0; $i < $cols; $i++) {
if (isset($skipped[$i])) {
$cells[$i] = '';
Expand All @@ -1274,6 +1274,7 @@ protected function getPageSummaryRow()
}
return implode('', $cells);
}

/**
* @inheritdoc
* @throws InvalidConfigException
Expand Down Expand Up @@ -1307,11 +1308,21 @@ public function renderTableRow($model, $key, $index)
} else {
$options = $this->rowOptions;
}
$options['data-key'] = is_array($key) ? json_encode($key) : (string) $key;
$options['data-key'] = static::parseKey($key);
Html::addCssClass($options, $this->options['id']);
return Html::tag('tr', implode('', $cells), $options);
}

/**
* Parses the key and returns parsed key value as string based on the data type
* @param mixed $key
* @return string
*/
public static function parseKey($key)
{
return is_array($key) ? Json::encode($key) : (is_object($key) ? serialize($key) : (string)$key);
}

/**
* Renders the toggle data button.
*
Expand Down Expand Up @@ -2119,8 +2130,8 @@ protected function renderToolbarContainer()
* forcing float-right only if no float is defined in toolbarContainerOptions
*/
if (
!strpos($this->toolbarContainerOptions['class'],$this->getCssClass(self::BS_PULL_RIGHT))
&& !strpos($this->toolbarContainerOptions['class'],$this->getCssClass(self::BS_PULL_LEFT))
!strpos($this->toolbarContainerOptions['class'], $this->getCssClass(self::BS_PULL_RIGHT))
&& !strpos($this->toolbarContainerOptions['class'], $this->getCssClass(self::BS_PULL_LEFT))
) {
$this->addCssClass($this->toolbarContainerOptions, self::BS_PULL_RIGHT);
}
Expand Down

0 comments on commit bfb16b4

Please sign in to comment.