⚠ 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 do I make a custom-column sortable



Shibu Menon
  • profile picture
  • Member

Posted 04 June 2015 - 09:50 AM

Hi,

In my controller function, I am adding a custom column called 'PC-MB', which doesnot exist in the database. The value is dynamically generated using other values in the row. Which works fine.

My question is - how do I make this column sortable. By default, it is not sortable.

Thanks

$this->load->library('grocery_crud');
        $crud = new grocery_CRUD();
        $crud->where('is_history',0);
        $crud->where('category',"HighwayStats");
        $crud->set_table('hwdata');
        $crud->order_by('last_update');
        $crud->set_subject('Highway Data');
        $crud->columns('name',  'last_update', 'PC-MB');
        $crud->callback_column('PC-MB',array($this, '_totalpc_callback') );


        $gcrud_output = $crud->render();

 


Paul Savostin
  • profile picture
  • Member

Posted 04 June 2015 - 10:47 AM

HI! Which theme you use? For example, i use datatables theme and sort by custom column easy enough, cause all records in view.


Shibu Menon
  • profile picture
  • Member

Posted 04 June 2015 - 11:59 AM

Thanks Paul. Yes, changing the theme to datatables enabled sorting


saitechnobrains
  • profile picture
  • Member

Posted 27 October 2018 - 19:14 PM

Hi Paul, I am facing same issue with bootstrap-v4 theme. 

My code:


$output = $this->grocery_crud
->set_subject('Customers')
->set_relation('state_id', $this->db->dbprefix . 'states', '{state_name}')
->columns(array('name','mobile_number','address','availble_points','status'))
->callback_column('address',array($this,'_callback_customer_address'))
->callback_column('availble_points',array($this,'_callback_availble_points'))
->fields(array('user_type','name','mobile_number','address_1','address_2','city','state_id','dob','marriage_date','status'))
->display_as('state_id','State name')
->field_type('user_type', 'hidden', 2)
->field_type('status','true_false', array(1 => 'Active', 2 => 'Inactive'))
->required_fields('user_type','name','mobile_number','address_1','city','state_id','dob','status')
->unique_fields(array('mobile_number'))
->callback_after_insert(array($this, '_callback_insert_bank_details'))
->add_action('Bank Details', '', 'admin/customer_bank_details','el el-plus')
->add_action('Barcode Redeemation', '', 'admin/barcode_redeemation','el el-plus')
->add_action('Point Redeemation', '', 'admin/point_redeemation','el el-plus')
->unset_delete()
->render();