Jump to content


waqar

Member Since 08 Sep 2012
Offline Last Active Sep 12 2012 09:58 AM
-----

Topics I've Started

How do I disable Sorting for certain Columns of CRUD grid?

11 September 2012 - 12:14 PM

Does anyone know how I can disable some certain columns from the CRUD?

Thanks

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

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

How to add custom field in edit/add view that doesn't exist in database?

11 September 2012 - 11:11 AM

I have a table of Transactions with columns like:
date
title
deposit
withdraw

I want to show the add/edit form the following fields:
date
title
amount
type (deposit or withdraw)

I want the user to select whether the type of this transaction he's adding is of deposit or withdraw, and then before insertion I want the system to figure out what user has selected, and then set the field value (either deposit or withdraw) to what he has chosen, from the field of amount.

But the problem is, I can't add a custom field to the add/edit form that doesn't exist in database, because if I do, the insertion of CRUD simply fails.

Here's some code snippet, can anyone help?
// Set title or subject of this CRUD
   $crud->set_subject('Transaction');
   // Set database table name for CRUD operations
   $crud->set_table('transactions');
   // Set Relation of tables for CRUD operations
   $crud->set_relation('category_id','category', 'title');
  
   // Columns for Grid
   $crud->columns('date','title','category_id', 'deposit', 'withdraw', 'balance');
   $crud->unset_fields('deposit','withdraw');
   // Order by
   $crud->order_by('date','asc');
  
   // Load custom Transactions_model
   $crud->set_model('Transactions_model');
  
   // Callbacks for columns on grid
   //$crud->callback_column('deposit',array($this,'transaction_type'));
   //$crud->callback_column('balance',array($this,'transaction_balance'));
  
   // Display field as
   $crud->display_as('title','Description');
   $crud->display_as('category_id','Category');
  
   // Fields for add/edit form
   //$crud->fields('date','title','deposit','withdraw','amount','category_id');
   // Hide some fields from add/edit form from user
   // $crud->change_field_type('deposit','invisible');
   // $crud->change_field_type('withdraw','invisible');
  
   // Required fields
   $crud->required_fields('date','title','category_id');
  
   // Callback on field on add/edit form
   //$crud->callback_before_insert(array($this,'amount_callback'));
   // Render Crud
   $output = $crud->render();
  
   // Load view
   $this->_transactions_output($output);