⚠ In case you've missed it we are migrating 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 forum is read-only and soon will be archived. ⚠


How do I make a custom-column sortable

custom column sortable

  • Please log in to reply
3 replies to this topic

#1 Shibu Menon

Shibu Menon

    Newbie

  • Members
  • Pip
  • 2 posts

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();

 



#2 Paul Savostin

Paul Savostin

    Advanced Member

  • Members
  • PipPipPip
  • 229 posts

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.



#3 Shibu Menon

Shibu Menon

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 04 June 2015 - 11:59 AM

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



#4 saitechnobrains

saitechnobrains

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 27 October 2018 - 07: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();






Also tagged with one or more of these keywords: custom column, sortable

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users