Datatable order by Month and Year

Viewed 45

Can i set datatable order by Month and Year ( where i get the data as "October 2021",...."February 2022" ). Refer the attached image for details

This is my code in controller where i get data .

 $fiveexpdata = Dairyexpense::select(DB::raw('DATE_FORMAT(expensesdate, "%M %Y") as "month_name",SUM(amount) as "amount"'))
          ->whereBetween('expensesdate', [Carbon::now()->subMonth(6),Carbon::now()->endOfMonth()])
          ->groupBy('month_name')
          ->get()
          ->toArray();

After Sending the same in datatable, it shows data in Oct 2021 Nov 2021 Dec 2021 Jan 2022 Feb 2022 March 2022

Where as i required the same in March 2022 Feb 2022 Jan 2022 Dec 2021 Nov 2021 Oct 2021

enter image description here

1 Answers
Related