Jump to content


Order by not working on datatables theme

order by datatables

  • Please log in to reply
2 replies to this topic

#1 amirrachman

amirrachman

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 03 October 2013 - 04: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/s...310a1c7021a495d

 

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

 

Cheers,

 

 

Amir Rachman



#2 davidoster

davidoster

    Grocery CRUD Ninja

  • Advanced Member
  • PipPipPip
  • 1,068 posts
  • LocationAthens, Greece

Posted 11 October 2013 - 04:53 AM

Hello and welcome to the forums amirrachman.

I would suggest you post on the github about this.


____________________________________________________________

 

rtfm_small.jpg---!!!Please read these guidelines before asking to the forums!!!---

____________________________________________________________

 

David Oster aka George Pasparakis,
http://odphotography.com
http://eletter.gr


#3 tomo

tomo

    Newbie

  • Members
  • Pip
  • 1 posts

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++;
		}
	}






Also tagged with one or more of these keywords: order by, datatables

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users