Buongiorno a tutti, stò tentando di rendere ordinabile la mia tabella di dati.
Ho implementato il codice sottostante, ma non ho capito come mi devo comportare con la query....
Per ora, l'header della tabella ha tutti i campi ordinabili (cioè compare la freccetta per scegliere se ordinare in modo Asc o Disc) ma non ho capito come implementare la query per farlo.
ecco il codice:
<?php
function provaOrdinamento_menu(){
$items['ordina']= array(
'title'=> 'Prova Ordinamento',
'page callback'=> 'get_ticket',
'access callback'=>TRUE,
);
return $items;
};
function get_ticket(){
$output = drupal_get_form('provaOrdinamento_form');
return $output;
};
function provaOrdinamento_form($node, &$form_state, $filtro1=NULL, $filtro2=NULL){
$tickets = get_tickets();
$form['tickets']= array(
'#type'=>'value',
'#value'=> $tickets,
'#theme' => 'tabella_provaOrdinamento',
);
return $form;
};
function provaOrdinamento_theme(){
return array(
'tabella_provaOrdinamento' => array(
array('render element' => 'tickets')),
);
}
function get_tickets(){
$rows = array();
$result= "";
$query= db_select("rgls_ticket", "r");
$query->fields("r", array("id","titolo", "descrizione"));
$query->extend('TableSort');
$result = $query->execute();
foreach ($result as $node) {
$rows[] = array(
$node->id,
$node->titolo,
$node->descrizione,
);
}
return $rows;
return $header;
}
function theme_tabella_provaOrdinamento($tickets){
$header = array(
array('data' => 'ID', 'field' => 'id'),
array('data' => 'Titolo', 'field' =>'titolo', 'sort' => 'ASC'),
array('data' => 'Descrizione', 'field' => 'descrizione'),
);
$rows = array();
foreach($tickets[""]["#value"] as $ticket){
$rows[] = $ticket;
}
$output = theme_table(
array("header" => $header,
"rows" => $rows,
"attributes" => array(),