Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding new feature columns_align to set alignment for displayed columns #253

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 74 additions & 1 deletion application/controllers/examples.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function customers_management()

$this->_example_output($output);
}

public function orders_management()
{
$crud = new grocery_CRUD();
Expand Down Expand Up @@ -245,5 +245,78 @@ public function customers_management2()
return $output;
}
}

public function column_align_right()
{
$crud = new grocery_CRUD();

$crud->set_table('customers');
$crud->columns('customerName','contactLastName','phone','city','country','salesRepEmployeeNumber','creditLimit');
$crud->columns_align(array('customerName' => 'right','contactLastName' => 'right','phone' => 'right','city' => 'right','country' => 'right','salesRepEmployeeNumber' => 'right','creditLimit' => 'right'));
$crud->display_as('salesRepEmployeeNumber','from Employeer')
->display_as('customerName','Name')
->display_as('contactLastName','Last Name');
$crud->set_subject('Customer');
$crud->set_relation('salesRepEmployeeNumber','employees','lastName');

$output = $crud->render();

$this->_example_output($output);
}

public function column_align_center()
{
$crud = new grocery_CRUD();

$crud->set_table('customers');
$crud->columns('customerName','contactLastName','phone','city','country','salesRepEmployeeNumber','creditLimit');
$crud->columns_align(array('customerName' => 'center','contactLastName' => 'center','phone' => 'center','city' => 'center','country' => 'center','salesRepEmployeeNumber' => 'center','creditLimit' => 'center'));
$crud->display_as('salesRepEmployeeNumber','from Employeer')
->display_as('customerName','Name')
->display_as('contactLastName','Last Name');
$crud->set_subject('Customer');
$crud->set_relation('salesRepEmployeeNumber','employees','lastName');

$output = $crud->render();

$this->_example_output($output);
}

public function column_align_right2()
{
$crud = new grocery_CRUD();

$crud->set_table('customers');
$crud->set_theme('datatables');
$crud->columns('customerName','contactLastName','phone','city','country','salesRepEmployeeNumber','creditLimit');
$crud->columns_align(array('customerName' => 'right','contactLastName' => 'right','phone' => 'right','city' => 'right','country' => 'right','salesRepEmployeeNumber' => 'right','creditLimit' => 'right'));
$crud->display_as('salesRepEmployeeNumber','from Employeer')
->display_as('customerName','Name')
->display_as('contactLastName','Last Name');
$crud->set_subject('Customer');
$crud->set_relation('salesRepEmployeeNumber','employees','lastName');

$output = $crud->render();

$this->_example_output($output);
}

public function column_align_center2()
{
$crud = new grocery_CRUD();

$crud->set_table('customers');
$crud->set_theme('datatables');
$crud->columns('customerName','contactLastName','phone','city','country','salesRepEmployeeNumber','creditLimit');
$crud->columns_align(array('customerName' => 'center','contactLastName' => 'center','phone' => 'center','city' => 'center','country' => 'center','salesRepEmployeeNumber' => 'center','creditLimit' => 'center'));
$crud->display_as('salesRepEmployeeNumber','from Employeer')
->display_as('customerName','Name')
->display_as('contactLastName','Last Name');
$crud->set_subject('Customer');
$crud->set_relation('salesRepEmployeeNumber','employees','lastName');

$output = $crud->render();

$this->_example_output($output);
}
}
48 changes: 44 additions & 4 deletions application/libraries/Grocery_CRUD.php
Original file line number Diff line number Diff line change
Expand Up @@ -3360,7 +3360,11 @@ class Grocery_CRUD extends grocery_CRUD_States
protected $state_code = null;
protected $state_info = null;
protected $columns = null;


// for column align's feature purpose
protected $columns_aligned = false;
protected $columns_align = null;

private $basic_db_table_checked = false;
private $columns_checked = false;
private $add_fields_checked = false;
Expand Down Expand Up @@ -3483,6 +3487,27 @@ public function columns()
return $this;
}

/** ------------------------------------------
* User can change the displayed columns align
* -------------------------------------------
* @access public
* @param array
* @return void
*/
public function columns_align($columns_align = array())
{
if( ! empty($columns_align) && is_array($columns_align))
{
foreach($columns_align as $col => $align)
{
$this->columns_align[$col] = $align;
}

$this->columns_aligned = TRUE;
}

return $this;
}

/**
* Set Validation Rules
Expand Down Expand Up @@ -4034,6 +4059,12 @@ protected function get_columns()
$new_column = $this->_unique_field_name($this->relation[$column][0]);
$this->columns[$col_num] = $new_column;

if ($this->columns_aligned && is_array($this->columns_align) && array_key_exists($column, $this->columns_align))
{
$align = $this->columns_align[$column];
$this->columns_align[$new_column] = $align;
}

if(isset($this->display_as[$column]))
{
$display_as = $this->display_as[$column];
Expand All @@ -4058,6 +4089,13 @@ protected function get_columns()
if( $relation[2] == $column )
{
$new_column = $table_name.'.'.$column;

if ($this->columns_aligned && is_array($this->columns_align) && array_key_exists($column, $this->columns_align))
{
$align = $this->columns_align[$column];
$this->columns_align[$new_column] = $align;
}

if(isset($this->display_as[$column]))
{
$display_as = $this->display_as[$column];
Expand All @@ -4078,12 +4116,14 @@ protected function get_columns()
}

if(isset($this->display_as[$column]))
$this->columns[$col_num] = (object)array('field_name' => $column, 'display_as' => $this->display_as[$column]);
$this->columns[$col_num] = (object)array('field_name' => $column, 'display_as' => $this->display_as[$column],
'align' => isset($this->columns_align[$column]) ? $this->columns_align[$column] : '');
elseif(isset($field_types[$column]))
$this->columns[$col_num] = (object)array('field_name' => $column, 'display_as' => $field_types[$column]->display_as);
$this->columns[$col_num] = (object)array('field_name' => $column, 'display_as' => $field_types[$column]->display_as,
'align' => isset($this->columns_align[$column]) ? $this->columns_align[$column] : '');
else
$this->columns[$col_num] = (object)array('field_name' => $column, 'display_as' =>
ucfirst(str_replace('_',' ',$column)));
ucfirst(str_replace('_',' ',$column)), 'align' => isset($this->columns_align[$column]) ? $this->columns_align[$column] : '');

if(!empty($this->unset_columns) && in_array($column,$this->unset_columns))
{
Expand Down
9 changes: 7 additions & 2 deletions application/views/example.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,13 @@
<a href='<?php echo site_url('examples/employees_management')?>'>Employees</a> |
<a href='<?php echo site_url('examples/film_management')?>'>Films</a> |
<a href='<?php echo site_url('examples/film_management_twitter_bootstrap')?>'>Twitter Bootstrap Theme [BETA]</a> |
<a href='<?php echo site_url('examples/multigrids')?>'>Multigrid [BETA]</a>

<a href='<?php echo site_url('examples/multigrids')?>'>Multigrid [BETA]</a>
</div>
<div>
<a href='<?php echo site_url('examples/column_align_right')?>'>Flexigrid - Column Align Right</a> |
<a href='<?php echo site_url('examples/column_align_center')?>'>Flexigrid - Column Align Center</a> |
<a href='<?php echo site_url('examples/column_align_right2')?>'>Datatables - Column Align Right</a> |
<a href='<?php echo site_url('examples/column_align_center2')?>'>Datatables - Column Align Center</a> |
</div>
<div style='height:20px;'></div>
<div>
Expand Down
6 changes: 4 additions & 2 deletions assets/grocery_crud/themes/datatables/views/list.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<thead>
<tr>
<?php foreach($columns as $column){?>
<th><?php echo $column->display_as; ?></th>
<?php $text_align = (empty($column->align) ? '' : ('style="text-align:'.$column->align.'"')); ?>
<th <?php echo $text_align;?>><?php echo $column->display_as; ?></th>
<?php }?>
<?php if(!$unset_delete || !$unset_edit || !$unset_read || !empty($actions)){?>
<th class='actions'><?php echo $this->l('list_actions'); ?></th>
Expand All @@ -13,7 +14,8 @@
<?php foreach($list as $num_row => $row){ ?>
<tr id='row-<?php echo $num_row?>'>
<?php foreach($columns as $column){?>
<td><?php echo $row->{$column->field_name}?></td>
<?php $text_align = (empty($column->align) ? '' : ('align="'.$column->align.'"')); ?>
<td <?php echo $text_align;?>><?php echo $row->{$column->field_name}?></td>
<?php }?>
<?php if(!$unset_delete || !$unset_edit || !$unset_read || !empty($actions)){?>
<td class='actions'>
Expand Down
6 changes: 4 additions & 2 deletions assets/grocery_crud/themes/flexigrid/views/list.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
<tr class='hDiv'>
<?php foreach($columns as $column){?>
<th width='<?php echo $column_width?>%'>
<div class="text-left field-sorting <?php if(isset($order_by[0]) && $column->field_name == $order_by[0]){?><?php echo $order_by[1]?><?php }?>"
<?php $text_align = "text-".(empty($column->align) ? 'left' : $column->align); ?>
<div class="<?php echo $text_align;?> field-sorting <?php if(isset($order_by[0]) && $column->field_name == $order_by[0]){?><?php echo $order_by[1]?><?php }?>"
rel='<?php echo $column->field_name?>'>
<?php echo $column->display_as?>
</div>
Expand All @@ -29,7 +30,8 @@
<tr <?php if($num_row % 2 == 1){?>class="erow"<?php }?>>
<?php foreach($columns as $column){?>
<td width='<?php echo $column_width?>%' class='<?php if(isset($order_by[0]) && $column->field_name == $order_by[0]){?>sorted<?php }?>'>
<div class='text-left'><?php echo $row->{$column->field_name} != '' ? $row->{$column->field_name} : '&nbsp;' ; ?></div>
<?php $text_align = "text-".(empty($column->align) ? 'left' : $column->align); ?>
<div class="<?php echo $text_align;?>"><?php echo $row->{$column->field_name} != '' ? $row->{$column->field_name} : '&nbsp;' ; ?></div>
</td>
<?php }?>
<?php if(!$unset_delete || !$unset_edit || !$unset_read || !empty($actions)){?>
Expand Down