Commits

Anonymous committed 794052d

added styles for grid view sorting and filters

  • Participants
  • Parent commits 3537fb0
  • Branches 1.0.0-wip

Comments (0)

Files changed (4)

File assets/css/yii-bootstrap.css

 }
 
 .grid-view table.items th a .caret {
+	display: none;
 	position: absolute;
 	right: 5px;
 	top: 7px;
 }
 
+.grid-view table.items th a.asc .caret {
+	display: block;
+}
+
 .grid-view table.items th a.desc .caret {
 	border-bottom: 4px solid #000;
 	border-top: none;
+	display: block;
 }
 
 .grid-view table.items tr.selected td {
 	font-style: italic;
 }
 
+.grid-view .filters .filter-container {
+	padding: 0 10px 0 0;
+}
+
 .grid-view .filters input,
 .grid-view .filters select {
-	border: none;
 	margin-bottom: 0;
-	padding: 0;
 	width: 100%;
-	box-shadow: none; -o-box-shadow: none; -moz-box-shadow: none; -ms-box-shadow: none; -webkit-box-shadow: none;
 }
 
 /*

File lib/bootstrap/less/mixins.less

 }
 // Reset filters for IE
 .reset-filter() {
-  filter: progid:DXImageTransform.Microsoft.gradient(enabled = false);
+  filter: e(%("progid:DXImageTransform.Microsoft.gradient(enabled = false)"));
 }
 
 

File widgets/BootDataColumn.php

+<?php
+/**
+ * BootDataColumn class file.
+ * @author Christoffer Niska <ChristofferNiska@gmail.com>
+ * @copyright Copyright &copy; Christoffer Niska 2011-
+ * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
+ * @package bootstrap.widgets
+ */
+
+Yii::import('zii.widgets.grid.CDataColumn');
+
+/**
+ * Bootstrap grid data column
+ */
+class BootDataColumn extends CDataColumn
+{
+	/**
+	 * Renders the header cell content.
+	 * This method will render a link that can trigger the sorting if the column is sortable.
+	 */
+	protected function renderHeaderCellContent()
+	{
+		if ($this->grid->enableSorting && $this->sortable && $this->name !== null)
+		{
+			$label = isset($this->header) ? $this->header : $this->grid->dataProvider->getSort()->resolveLabel($this->name);
+			$label .= '<span class="caret"></span>';
+			echo $this->grid->dataProvider->getSort()->link($this->name, $label);
+		}
+		else
+		{
+			if ($this->name !== null && $this->header === null)
+			{
+				if ($this->grid->dataProvider instanceof CActiveDataProvider)
+					echo CHtml::encode($this->grid->dataProvider->model->getAttributeLabel($this->name));
+				else
+					echo CHtml::encode($this->name);
+			}
+			else
+				parent::renderHeaderCellContent();
+		}
+	}
+
+	/**
+	 * Renders the filter cell.
+	 */
+	public function renderFilterCell()
+	{
+		echo '<td><div class="filter-container">';
+		$this->renderFilterCellContent();
+		echo '</div></td>';
+	}
+}

File widgets/BootGridView.php

  */
 
 Yii::import('zii.widgets.grid.CGridView');
+Yii::import('bootstrap.widgets.BootDataColumn');
 
 /**
  * Bootstrap grid view widget.
 
 		$this->itemsCssClass .= ' '.implode(' ', $class);
 	}
+
+	/**
+	 * Creates column objects and initializes them.
+	 */
+	protected function initColumns()
+	{
+		foreach ($this->columns as $i => $column)
+		{
+			if (is_array($column) && !isset($column['class']))
+				$this->columns[$i]['class'] = 'bootstrap.widgets.BootDataColumn';
+		}
+
+		parent::initColumns();
+	}
+
+	/**
+	 * Creates a column based on a shortcut column specification string.
+	 * @param mixed $text the column specification string
+	 * @return \BootDataColumn|\CDataColumn the column instance
+	 * @throws CException if the column format is incorrect
+	 */
+	protected function createDataColumn($text)
+	{
+		if (!preg_match('/^([\w\.]+)(:(\w*))?(:(.*))?$/', $text, $matches))
+			throw new CException(Yii::t('zii', 'The column must be specified in the format of "Name:Type:Label", where "Type" and "Label" are optional.'));
+
+		$column = new BootDataColumn($this);
+		$column->name = $matches[1];
+		if (isset($matches[3]) && $matches[3] !== '')
+			$column->type = $matches[3];
+
+		if (isset($matches[5]))
+			$column->header = $matches[5];
+
+		return $column;
+	}
 }