I have an EntityFieldQuery that gets displayed in a table. How do I add clickable sort-by-column functionality? When I use regular db_select queries I can sort using the following code:
$query = db_select('tablename', 't')
->extend('PagerDefault')
->limit(50)
->extend('TableSort')
// ...
$query = $query->orderByHeader($header)
$results = $query->execute();
Everything looks good and when the table is displayed I can click on the columns and they are hyperlinks and I can sort just fine. However, now that I have an EntityFieldQuery I can't seem to duplicate the functionality. This is what I have so far:
$header = array(
'title' => array(
'data' => t('Date'),
'type' => 'field',
'specifier' => array(
'field' => 'field_articledate',
'column' => 'value',
),
),
);
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
->entityCondition('bundle', 'article')
->propertyCondition('status', 1);
$query = $query->tableSort($header);
$query = $query->pager(100);
$results = $query->execute();
A one-column header appears and it says "Date" as expected, but it is not a clickable hyperlink. What am I doing wrong? What is the correct syntax?