⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

how to add autonumber column in flexigrid theme



itfreelancer
  • profile picture
  • Member

Posted 07 November 2012 - 03:35 AM

Hi all, i am a beginner in grocery crud, i have a problem when i add new column for auto number in flexygrid theme.

here my code in file list.php

$no = 0;
foreach($list as $num_row => $row){ ?>
<tr <?php if($num_row % 2 == 1){?>class="erow"<?php }?>>
<?php
$no++;
?>
<td width='5%'><div class='text-left'><?php echo $no;?></div></td>

........

it is work if in page 1, but in the next page, the auto number start from 1 again.

Thanks

victor
  • profile picture
  • Member

Posted 07 November 2012 - 12:46 PM

Hi, itfreelancer and welcome to the forum.

try this:

if($this->input->post('page')
{
$no = $this->input->post('page')*($this->input->post('per_page')-1)
}
else
{
$no = 0;
}

foreach($list as $num_row => $row){ ?>
<tr <?php if($num_row % 2 == 1){?>class="erow"<?php }?>>
<?php
$no++;
?>
<td width='5%'><div class='text-left'><?php echo $no;?></div></td>

itfreelancer
  • profile picture
  • Member

Posted 07 November 2012 - 20:39 PM

Hi, thanks for your replay. when i try your code, i get error

Severity: Notice
Message: Undefined property: grocery_CRUD::$input
Filename: views/list.php
Line Number: 34

here code in list.php

if($this->input->post('page'))
{
$no = $this->input->post('page')*($this->input->post('per_page')-1);
}
else
{
$no = 0;
}
foreach($list as $num_row => $row){ ?>
<tr <?php if($num_row % 2 == 1){?>class="erow"<?php }?>>
<?php
$no++;
?>
<td width='5%'><div class='text-left'><?php echo $no;?></div></td>
<?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} : ' ' ; ?></div>
</td>
<?php }?>
<?php if(!$unset_delete || !$unset_edit || !empty($actions)){?>
<td align="left" width='20%'>
<div class='tools'>
<?php if(!$unset_delete){?>
<a href='<?php echo $row->delete_url?>' title='<?php echo $this->l('list_delete')?> <?php echo $subject?>' class="delete-row" >
<span class='delete-icon'></span>
</a>
<?php }?>
<?php if(!$unset_edit){?>
<a href='<?php echo $row->edit_url?>' title='<?php echo $this->l('list_edit')?> <?php echo $subject?>'><span class='edit-icon'></span></a>
<?php }?>
<?php
if(!empty($row->action_urls)){
foreach($row->action_urls as $action_unique_id => $action_url){
$action = $actions[$action_unique_id];
?>
<a href="<?php echo $action_url; ?>" class="<?php echo $action->css_class; ?> crud-action" title="<?php echo $action->label?>"><?php
if(!empty($action->image_url))
{
?><img src="<?php echo $action->image_url; ?>" alt="<?php echo $action->label?>" /><?php
}
?></a>
<?php }
}
?>
<div class='clear'></div>
</div>
</td>
<?php }?>
</tr>
<?php } ?>


and code in list_template.php

<div class="pGroup">
<span class="pcontrol"><?php echo $this->l('list_page'); ?> <input name='page' type="text" value="1" size="4" id='crud_page'>
<?php echo $this->l('list_paging_of'); ?>
<span id='last-page-number'><?php echo ceil($total_results / $default_per_page)?></span></span>
</div>
<div class="btnseparator">
</div>
<div class="pGroup">
<div class="pNext pButton next-button" >
<span></span>
</div>
<div class="pLast pButton last-button">
<span></span>
</div>
</div>
<div class="btnseparator">
</div>
<div class="pGroup">
<div class="pReload pButton" id='ajax_refresh_and_loading'>
<span></span>
</div>
</div>
<div class="btnseparator">
</div>
<div class="pGroup">
<span class="pPageStat">
<?php $paging_starts_from = "<span id='page-starts-from'>1</span>"; ?>
<?php $paging_ends_to = "<span id='page-ends-to'>". ($total_results < $default_per_page ? $total_results : $default_per_page) ."</span>"; ?>
<?php $paging_total_results = "<span id='total_items'>$total_results</span>"?>
<?php echo str_replace( array('{start}','{end}','{results}'),
array($paging_starts_from, $paging_ends_to, $paging_total_results),
$this->l('list_displaying')
); ?>
</span>
</div>

victor
  • profile picture
  • Member

Posted 07 November 2012 - 20:43 PM

try :
$ci = &get_instance();

if($ci->input->post('page'))
{
$no = $ci->input->post('page')*($this->input->post('per_page')-1);
}
else
{
$no = 0;
}

itfreelancer
  • profile picture
  • Member

Posted 07 November 2012 - 23:56 PM

Thanks for replay. The code is work for me.

here my new code

$ci = &amp;get_instance();

if($ci->input->post('page'))
{
$no = ($ci->input->post('page')-1)*$ci->input->post('per_page');
}
else
{
$no = 0;
}


Thanks you very much.