Berdir 덕분에 작동했습니다. 이것이 더 자세하게 작동하는 방법입니다.
$ headers 배열의 (열) 배열에 'data', 'field'및 선택적으로 'sort'키가 포함되어 있으면 Tablesort가 "자동으로"트리거됩니다. 열 머리글에 '정렬'과 '순서'가있는 링크가 만들어지고 작은 화살표 등이 표시됩니다.
자체 정렬을 수행하려면 tablesort_get_order 및 tablesort_get_sort 를 사용 하여 현재 정렬 설정을 가져 와서 자체 정렬 기능에 해당 값을 사용하십시오. tablesort_get_order가 반환 한 배열의 키 'sql'에는 정렬에 사용할 필드 이름이 포함되어 있습니다.
각 사용자에 대한 세부 정보가 포함 된 $ users 배열이 포함 된 (예상치 않은) 예제 코드 :
// setup the table data that we want to show
$tableData = array();
foreach ($users as $userDetails) {
$tableData[] = array(
'name' => $userDetails['name'],
'visits' => $userDetails['visits'],
'views' => $userDetails['views'],
'comments' => $userDetails['comments']
);
}
// headers array, sorting by default on comments
$headers = array(
array('data' => t('Name'), 'field' => 'name'),
array('data' => t('Visits'), 'field' => 'visits'),
array('data' => t('Views'), 'field' => 'views'),
array('data' => t('Comments'), 'field' => 'comments', 'sort' => 'desc')
);
// getting the current sort and order parameters from the url
$order = tablesort_get_order($headers);
$sort = tablesort_get_sort($headers);
// sort the table data accordingly (write your own sort function)
$tableData = my_array_sort($tableData, $order['sql'], $sort);
// create the array with rows for theme table
$rows = array();
foreach ($tableData as $entry) {
$rows[] = array(
array('data' => $entry['name']),
array('data' => $entry['visits']),
array('data' => $entry['views']),
array('data' => $entry['comments']),
);
}
// add any attributes and sent everything to theme table
$attributes = array('class' => array('my_class'));
$table = array('header' => $headers, 'attributes' => $attributes, 'rows' => $rows);
$html = theme('table', $table);