It seems like TableSort extender fails to recognize correctly the column to sort on when the column title contains spaces. e.g. consider the following $headers section:
$headers = array(
array(
'data' => t('Type'),
'field' => 'd.type',
'class' => array('search-result-header col-type')),
array(
'data' => t('Title'),
'field' => 'title',
'sort' => 'asc',
'class' => array('search-result-header col-title')),
array(
'data' => t('Author'),
'field' => 'author',
'class' => array('search-result-header col-author')),
array(
'data' => t('Year of Publication'),
'field' => 'publish_year',
'class' => array('search-result-header col-publish-year')),
array(
'data' => t('Keywords'),
'class' => array('search-result-header col-keywords')),
array(
'data' => '',
'class' => array('search-result-header col-download')));
The link for "Year of Publishing" header is generated as:
/drupal/?q=document&sort=asc&order=Year%20of%20Publication
But clicking on that link any number of times always sorts in ascending order by the "Title" column. If I remove spaces from "Year of Publishing" header, it starts working fine.
Comments
Comment #1
ankur commentedThis is actually a bug in the document module.
If you hover over the 'Year of Publication' table-sort link, and copy and paste that URL into another browser window, you get the expected behavior.
However, if you click the link on the documents (as in $_GET['q'] == 'documents') page itself, there is some Javascript on the page from the document module that does the event handling for the click and seems to change the URL as well as double-encode the parameters in the URL.
When I click on the table-sort link, my browser is actually sending the following URL, as a result of the javascript's rewriting of it:
q=document/search&_=1336770015617&criteria=%7B%22searchText%22%3A%22%22%2C%22searchFields%22%3A%223%22%2C%22searchYear%22%3A%22%22%2C%22searchDocType%22%3A%22%22%7D&page=0&sort=asc&order=Year%2520of%2520Publication&validationString=%40MDRIxVrjN&validationToken=xsoEDvICfJuOCyjDXJTglz6Ea0z9DwJTguzqWmnr6ANotice that the
Year%20of%20Publicationhas becomeYear%2520Of%2520PublicationLooks like the javascript is somehow double-encoding the URL, turning the '%' into '%25'.
Comment #2
mamta_kamboj commented