| 7 entity.inc | public EntityFieldQuery::tableSort(&$headers) |
| 8 entity.query.inc | public EntityFieldQuery::tableSort(&$headers) |
Enable sortable tables for this query.
Parameters
$headers: An EFQ Header array based on which the order clause is added to the query.
Return value
EntityFieldQuery The called object.
File
- includes/
entity.inc, line 992
Code
public function tableSort(&$headers) {
// If 'field' is not initialized, the header columns aren't clickable
foreach ($headers as $key => $header) {
if (is_array($header) && isset($header['specifier'])) {
$headers[$key]['field'] = '';
}
}
$order = tablesort_get_order($headers);
$direction = tablesort_get_sort($headers);
foreach ($headers as $header) {
if (is_array($header) && ($header['data'] == $order['name'])) {
if ($header['type'] == 'field') {
$this->fieldOrderBy($header['specifier']['field'], $header['specifier']['column'], $direction);
}
else {
$header['direction'] = $direction;
$this->order[] = $header;
}
}
}
return $this;
}
Login or register to post comments
Comments
Structure of $headers
I'm trying to use this method but I don't know what datas $headers must have. It's seems that $headers doesn't look like $headers used in theme_table.
What means "An EFQ Header" ?
Thanks,
Fab.
An example
Here's an example I extracted from modules/simpletest/tests/entity_query.test:
$headers = array('myproperty' => array(
'data' => 'TableColumnName1',
'type' => 'property',
'specifier' => 'title',
),
'myfield1' => array(
'data' => 'TableColumnName2',
'type' => 'field',
'specifier' => array('field' => 'field_my_field1', 'column' => 'value'),
),
'myfield2' => array(
'data' => 'TableColumnName3',
'type' => 'field',
'specifier' => array('field' => 'field_my_field2', 'column' => 'value'),
'sort' => 'desc', # sort by this column by default
),
);