CMS NetCat - Sorting objects in a table
I offer my solution for sorting component objects presented in the form of a table. I use it often enough, maybe it will be useful to someone.
1. Change the column heading to a function that will substitute the desired link here Message_ID - the field by which we will sort, ID - column name the sort_header () function is described in the default module "; } return $ out; } Here everything is simple. We pass three parameters to the function: sorting field, column name and flag, hyphenation to the title is allowed or not. By default they are prohibited. 2. For sorting to work, you need to change the request. To do this, in the component settings, write: sort_set () we describe in the default module Everything.
In total, for sorting, it is necessary to supplement the system with two functions, after which the column headings should be changed to call one of them and specify the other in the component settings. It seems not difficult. I would be glad if someone comes in handy.
1. Change the column heading to a function that will substitute the desired link here Message_ID - the field by which we will sort, ID - column name the sort_header () function is described in the default module "; } return $ out; } Here everything is simple. We pass three parameters to the function: sorting field, column name and flag, hyphenation to the title is allowed or not. By default they are prohibited. 2. For sorting to work, you need to change the request. To do this, in the component settings, write: sort_set () we describe in the default module Everything.
".sort_header('Message_ID','ID')."
function sort_header($fild,$header, $wrap=0){
global $sub,$cc,$sort,$order;
/*
* Убираем из URI параметры sort, order, sid.
* Остальные надо оставить, т.к. в них может быть много полезного, например в беке или фронте открываем
* или данные фильтра
*/
$param="";
$separator='?';
foreach ($_GET as $key => $value) {
if($key!='sort' && $key!='order' && $key!='sid')
{
$param .=$separator.$key."=".$value;
$separator='&';
}
}
// Собераем ссылку.
if($wrap==0)
{
$out .="";
}
$out .="
{
$out .="&order=ASC";
}
$out .="'>$header";
$out .="";
if($sort==$fild && $order =='ASC')
{
$out .=" ";
}
elseif($sort==$fild)
{
$out .=" ";
}
if($wrap==0)
{
$out .="
$query_order = sort_set();
function sort_set(){
global $inside_admin,$sort,$order,$classID;
// узнаем есть ли в этой таблице такой столбец. Если этого не сделать, то на сайте могут быть ошибки
$sql = "SHOW COLUMNS FROM Message".$classID." WHERE Field = '".$sort."'";
$result = mysql_query($sql);
$num_rows = mysql_num_rows($result);
if($num_rows == 1)
{
if($order=='ASC')
{
$order = 'ASC';
}
else
{
$order = 'DESC';
}
// Собираем строку, которая будет дополненна в $query_order
$out="a.".$sort." ".$order;
return $out;
}
else
{
return;
}
}
In total, for sorting, it is necessary to supplement the system with two functions, after which the column headings should be changed to call one of them and specify the other in the component settings. It seems not difficult. I would be glad if someone comes in handy.