How do I create a custom field in Grid bottom, to show a Total Amount of XYZ amounts in the grid?
- Single Page
Posted 11 September 2012 - 12:10 PM
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
Posted 11 September 2012 - 18:25 PM
// 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
Posted 11 September 2012 - 22:02 PM
<div id='ajax_list'>
<?php echo $list_view?>
//here
</div>
After that use CI database class to populate the data.
Posted 12 September 2012 - 06:31 AM
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.
Posted 19 December 2012 - 12:08 PM
$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 [color=#333333][font='Lucida Grande', Verdana, Geneva, sans-serif]as string rather than sending it to your browser.[/font][/color]
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;
}
Posted 19 December 2012 - 12:46 PM
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.