Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines
Hi thanks for the quick reply. The values I wanted to sort are strings of month and year as in the example above of February 2021 and April 2021 and I would like to know if there is a way to sort by date (if necessary I will change the format in the database to date and not string)
Since the "month" column can't be sorted by its value, we need another column based on its value, which can be sorted. Pls try this code:
DataTables::create(array(
...
"columns" => array(
...
"standardMonth" => array(
"visible" => false, //no need to show this column
"formatValue" => function($row, $row, $colKey) {
$month = $row["month"];
$standardMonth = convertMonthYear($month); // use DateTime class to convert $month to standard date value, such as "2021-01-31", or just a simple year month "2021-01"
return $standardMonth;
}
),
"month" => array(
"data-order" => "standardMonth", //order this column by "standardMonth" column
)
)
));
Let us know if you have any further question. Rgds,
I forgot to mention, this line is a mocked up code:
$month = $row["month"];
$standardMonth = convertMonthYear($month);
It meant you'd have to write your own code to convert from your month and/or year to a standard date format string like "2021-01-31", which we use to sort by. I don't know exactly your original month date value so I can't give specific guidance.
Let KoolReport help you to make great reports. It's free & open-source released under MIT license.
Download KoolReport View demo