⚠ 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

Create a sequence number in a table



sofwan
  • profile picture
  • Member

Posted 27 June 2012 - 03:52 AM

Hi all ...

I want to put sequence number in a table. In ordinary CI, i usually make it in a View with create a variabel in looping and add increment. How to make it in Grocery Crud ?. I have tried with $crud->callback_column but not succeed yet.

Thank you in Advance.

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 27 June 2012 - 06:44 AM

Go to assets/grocery_crud/themes/flexigrid/views/list.php at around line 10 and change the:


<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 }?>"
rel='<?php echo $column->field_name?>'>
<?php echo $column->display_as?>
</div>
</th>
<?php }?>
<?php if(!$unset_delete || !$unset_edit || !empty($actions)){?>
<th align="left" abbr="tools" axis="col1" class="" width='20%'>
<div class="text-right">
<?php echo $this->l('list_actions'); ?>
</div>
</th>
<?php }?>
</tr>


to


<tr class='hDiv'>
<th width="20">
<div class="text-left field-sorting">
#
</div>
</th>
<?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 }?>"
rel='<?php echo $column->field_name?>'>
<?php echo $column->display_as?>
</div>
</th>
<?php }?>
<?php if(!$unset_delete || !$unset_edit || !empty($actions)){?>
<th align="left" abbr="tools" axis="col1" class="" width='20%'>
<div class="text-right">
<?php echo $this->l('list_actions'); ?>
</div>
</th>
<?php }?>
</tr>


and at around line 29 change the :


<?php foreach($list as $num_row => $row){ ?>
<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 style="width: 100%;" class='text-left'><?php echo $row->{$column->field_name}; ?></div>
</td>
<?php }?>


to


<?php foreach($list as $num_row => $row){ ?>
<tr <?php if($num_row % 2 == 1){?>class="erow"<?php }?>>
<td><?php echo ($num_row + 1);?></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 style="width: 100%;" class='text-left'><?php echo $row->{$column->field_name}; ?></div>
</td>
<?php }?>

likhon3k
  • profile picture
  • Member

Posted 18 October 2015 - 07:33 AM

Go to assets/grocery_crud/themes/flexigrid/views/list.php at around line 10 and change the:
 

   <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 }?>"
	  rel='<?php echo $column->field_name?>'>
	  <?php echo $column->display_as?>
	 </div>
    </th>
    <?php }?>
    <?php if(!$unset_delete || !$unset_edit || !empty($actions)){?>
    <th align="left" abbr="tools" axis="col1" class="" width='20%'>
	 <div class="text-right">
	  <?php echo $this->l('list_actions'); ?>
	 </div>
    </th>
    <?php }?>
   </tr>
to

   <tr class='hDiv'>
    <th width="20">
	 <div class="text-left field-sorting">
	  #
	 </div>
    </th>
    <?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 }?>"
	  rel='<?php echo $column->field_name?>'>
	  <?php echo $column->display_as?>
	 </div>
    </th>
    <?php }?>
    <?php if(!$unset_delete || !$unset_edit || !empty($actions)){?>
    <th align="left" abbr="tools" axis="col1" class="" width='20%'>
	 <div class="text-right">
	  <?php echo $this->l('list_actions'); ?>
	 </div>
    </th>
    <?php }?>
   </tr>
and at around line 29 change the :

<?php foreach($list as $num_row => $row){ ?>	   
  <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 style="width: 100%;" class='text-left'><?php echo $row->{$column->field_name}; ?></div>
   </td>
   <?php }?>
to

<?php foreach($list as $num_row => $row){ ?>	   
  <tr  <?php if($num_row % 2 == 1){?>class="erow"<?php }?>>
   <td><?php echo  ($num_row + 1);?></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 style="width: 100%;" class='text-left'><?php echo $row->{$column->field_name}; ?></div>
   </td>
   <?php }?>

 

Thank You for your solution :) I thought it is big coding....but found the actual changes in your code for row number...

 

<tr class='hDiv'>
<th width="20">
     <div class="text-left field-sorting">
     #
    
</div>
</th>

 

and

 

<td><?php echo ($num_row + 1);?></td>


coffeeDrunker6
  • profile picture
  • Member

Posted 24 May 2017 - 07:10 AM

Hi guys,

I did changes all the requirement to create rows number at assets/grocery_crud/themes/datatables/views/list.php. And i got my row number.

my default data order from database is by date. but when i'm sorting the data based on for example person name, the sequence of the row number is not order (for example: 3, 116, 54, 32, etc).

 

That i want to do is, when i'm sorting the data, the row number still in sequence number in (1,2,3,4 etc).

Is it possible to do that?

 

Sorry if my English bad.

Thanks a lot.