Jump to content


How do I create a custom field in Grid bottom, to show a Total Amount of XYZ amounts in the grid?

custom field field grid total field total

  • Please log in to reply
5 replies to this topic

#1 waqar

waqar

    Member

  • Members
  • PipPip
  • 10 posts

Posted 11 September 2012 - 12:10 PM

I have a grid that shows values something like:

Date of Transaction, Title of Transaction, Deposit Amount, Withdraw Amount

As you can see, it's a table of Transactions that either get Withdrawn or Deposited to some account.

I want to be able to do show a TOTAL Balance field in the Grid in the last row perhaps, and sum up the amounts and show the Total there. Not sure how to add that Row and column, any ideas?

Thanks
Waqar

#2 waqar

waqar

    Member

  • Members
  • PipPip
  • 10 posts

Posted 11 September 2012 - 06:25 PM

Currently what I'm doing is simply printing a Balance field outside CRUD. For example:

// Render Crud
   $output = $crud->render();
   // Get Total
   $output->total = $this->Transactions_model->get_total();

And I simply print out the $total variable in the relevant view file such as:
<div id="total">
  <label id="total">AVAILABLE BALANCE = </label>
  <span><?php echo $total; ?></span>
</div>

But it would be great if I can simply add a row in bottom of the CRUD grid that spans all columns and is aligned right and I print the total there.

Any ideas for this would be appreciated.

Thanks
Waqar

Web and Software Product Development Experts, Consultants, and IT Service Provider: 4 Ace Technologies

#3 midnigther

midnigther

    Advanced Member

  • Members
  • PipPipPip
  • 44 posts
  • LocationPortugal

Posted 11 September 2012 - 10:02 PM

You could put the current sum in the list_template.php.

<div id='ajax_list'>
<?php echo $list_view?>
	    //here
</div>

After that use CI database class to populate the data.
"Genius is 1% inspiration and 99% perspiration." - Thomas Edison

#4 waqar

waqar

    Member

  • Members
  • PipPip
  • 10 posts

Posted 12 September 2012 - 06:31 AM

Thanks, that seems good. 1 Question though, how do I pass the variable to the view list_template.php ?
What I pass is simply rendered on the custom view page (transactions.php in my case) and list_template.php is a core view for the CRUD Grid. I hope I'm able to explain well but let me know if not. Hope to get some help on this.

Thanks in advance.

#5 Fouzi

Fouzi

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 19 December 2012 - 12:08 PM

You can render a custom footer only when the grid state is a a list or after success update
$output = $crud->render();
$data = $this->get_footer_data();
$state = $crud->getState();

if ($state == 'list' || $state == 'success')
$output->footer = $this->load->view('footer_view',$data, TRUE);
$this->load->view('crud_view',$output);

See that I used a third parameter in load->view which returning views as string rather than sending it to your browser.

The footer data can be calculated in a separate function

function get_footer_data()
{
$data['total'] =$this->Transactions_model->get_total()
$data['taxe'] =$this->Transactions_model->get_taxe();
return $data;
}

in the crud view, we will render the footer only if it is set

crud_view.php
<div>
<?php echo $output; ?>
</div>
<? if (isset($footer)):?>
<div>
	 <?php echo $footer; ?>
</div>
<? endif; ?>

We can make the footer similar to the flexigrid cells using the same classes

footer_view.php
<div class="grid-footer flexigrid">
<div class ="bDiv">
<table cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<td><div>TOTAL </div></td>
<td><div class="text-right"><?=$total?></div></td>
</tr>
<tr class="erow">
<td><div>TAXE % </div></td>
<td><div class="text-right"><?=$taxe?></div></td>
</tr>
</tbody>
</table>
</div>
</div>

style.css
.grid-footer {
float : right;
width : 350px;
}
.grid-footer table{
width : 100%;
}
.flexigrid div.bDiv table {
margin-bottom: 0;
}


#6 Fouzi

Fouzi

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 19 December 2012 - 12:46 PM

You can add total to the CRUD Grid on the footer of the table without modifying the list_template.php
Just use CSS like that

.grid-footer {
position: relative;
top: -28px;
float : right;
width : 100px;
}

.grid-footer .pGroup {
   padding-top: 5px;
}

footer_view.php
<div class="grid-footer flexigrid">
    <div class="btnseparator"></div>
    <div class="pGroup">
    <span class="pPageStat">
    Total : <?=$total?>
    </span>
    </div>
</div>

It will be nice to have in future versions the possibility to add actions buttons, labels, fields to the grid footer like we do on grid rows.





Also tagged with one or more of these keywords: custom field, field, grid, total field, total

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users