⚠ 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

Order by not working on datatables theme



amirrachman
  • profile picture
  • Member

Posted 03 October 2013 - 16:55 PM

Hi All,

 

I am newbie on grocery crud, i want to ask about "order_by" function on datatable theme, it's not working for descending order.

i am using grocery crud version 1.4.1

 

PFB my code.

 

public function sic() {
   
        $crud = new grocery_CRUD();
        $crud->set_subject('SIC')
             ->set_table('im_sic')
             ->set_theme('datatables')
             ->set_relation('sic','im_master_member','member')
             ->columns('ID','sic_id','sic','from_date','end_date')
             ->fields('ID','sic_id','sic','from_date','end_date')
             ->order_by('ID','desc')
             ->callback_add_field('sic_id',array($this,'add_callback_sic_id'))
             ->unset_read()
             ->add_action('Print', '', 'shift/print','ui-icon-plus')
             ->add_action('Sic Incident', '', 'shift/incident','ui-icon-plus')
             ->add_action('Sic PW', '', 'shift/plannedwork','ui-icon-plus');
            
        if ($this->session->userdata('usergroup') == 'User') {
                 $crud->unset_operations();
             }
            
        //define title
        $data=array();
        $data['title']='Shift in Charge';    
                
        $output = $crud->render();

        //creating the title
        $output->data=$data;
    
        $this->shift_output($output);
    }

 

 

i read suggestion from scoumbourdis on the forum, already applied on the core, but still not working.

 

https://github.com/scoumbourdis/grocery-crud/commit/f37a7948683be57321d1d502a310a1c7021a495d

 

Please gave suggestions for this issue, i want the last data input shown on the 1st record.

 

Cheers,

 

 

Amir Rachman


davidoster
  • profile picture
  • Member

Posted 11 October 2013 - 04:53 AM

Hello and welcome to the forums [member=amirrachman].

I would suggest you post on the github about this.


tomo
  • profile picture
  • Member

Posted 21 August 2015 - 12:53 PM

Hi there,

I found a solution, in core fix change if statement to: ($num variable was used as a counter, but it is not good counter, so I added new one :-) )

if(!empty($order_by))
	{
                            $counter = 0; //edit
		foreach($columns as $num => $column) {
                        //echo $counter; //0125678
			if($column->field_name == $order_by[0]) {
				$ordering = $counter; //edit
				$sorting = isset($order_by[1]) && $order_by[1] == 'asc' || $order_by[1] == 'desc' ? $order_by[1] : $sorting ;
                                                                                            
			}
                                                                        $counter++;
		}
	}