PDA

Просмотр полной версии : Сортировка в таблице


SoulBurn
15.10.2008, 18:37
class.tx_test_pi1.php
<?php
require_once(PATH_tslib.'class.tslib_pibase.php');
class tx_test_pi1 extends tslib_pibase {
var $prefixId = 'tx_test_pi1'; // Same as class name
var $scriptRelPath = 'pi1/class.tx_test_pi1.php'; // Path to this script relative to the extension dir.
var $extKey = 'test'; // The extension key.
var $pi_checkCHash = true;
var $order;
function main($content,$conf) {

$this->conf=$conf;
$this->pi_setPiVarDefaults();
$this->pi_loadLL();

$content = $this->displayList();

return $this->pi_wrapInBaseClass($content);
}


function displayList($content,$conf) {

if (isset($this->piVars['age'])) $this->order = 'age';

$this->templateCode = $this->cObj->fileResource('EXT:test/res/test_template.html');

$template = array();
$template['total'] = $this->cObj->getSubpart($this->templateCode,'###TEST_TEMPLATE###');
$template['singlerow'] = $this->cObj->getSubpart($template['total'],'###SINGLEROW###');
$template['row'] = $this->cObj->getSubpart($template['singlerow'],'###ITEM###');
$template['row_alt'] = $this->cObj->getSubpart($template['singlerow'],'###ITEM_ALT###');

$marker = array();
$marker['###TEST_HID###'] = $this->pi_getLL('id');
$marker['###TEST_HNAME###'] = $this->pi_getLL('name');
$marker['###TEST_HLNAME###']= $this->pi_getLL('lname');
$marker['###TEST_HAGE###'] = $this->pi_getLL('age');

$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,name,last_name,age','tx_test _db','',$this->order);

$switch_row = 0;
while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {

$marker['###TEST_ID###'] = $row['uid'];
$marker['###TEST_NAME###'] = $row['name'];
$marker['###TEST_LNAME###'] = $row['last_name'];
$marker['###TEST_AGE###'] = $row['age'];

$switch_row = $switch_row ^ 1;
if($switch_row) {
$content_item .= $this->cObj->substituteMarkerArrayCached($template['row'], $marker);
} else {
$content_item .= $this->cObj->substituteMarkerArrayCached($template['row_alt'], $marker);
}
}

$subpartArray['###SINGLEROW###'] = $content_item;

$content = $this->cObj->substituteMarkerArrayCached($template['total'],$marker,$subpartArray);

return $content;
}

}

if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/test/pi1/class.tx_test_pi1.php']) {
include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/test/pi1/class.tx_test_pi1.php']);
}

?>

test_template.html
<!-- ###TEST_TEMPLATE### begin -->
<table width=100% class="table">
<tr class="table-header">
<th>###TEST_HID###</th>
<th>###TEST_HNAME###</th>
<th>###TEST_HLNAME###</th>
<th>
<input type="submit" value="###TEST_HAGE###" class="tx-test-button" name="tx_test_pi1[age]" />
</th>
</tr>
<!-- ###SINGLEROW### -->
<!-- ###ITEM### -->
<tr class="table-body1">
<th>###TEST_ID###</th>
<th>###TEST_NAME###</th>
<th>###TEST_LNAME###</th>
<th>###TEST_AGE###</th>
</tr>
<!-- ###ITEM### -->
<!-- ###ITEM_ALT### -->
<tr class="table-body2">
<th>###TEST_ID###</th>
<th>###TEST_NAME###</th>
<th>###TEST_LNAME###</th>
<th>###TEST_AGE###</th>
</tr>
<!-- ###ITEM_ALT### -->
<!-- ###SINGLEROW### -->
<tr class="table-footer">
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
</table>
<!-- ###TEST_TEMPLATE### end -->

надо, чтобы при нажатии на кнопку (<input type="submit" value="###TEST_HAGE###" class="tx-test-button" name="tx_test_pi1[age]" />) сортировало таблицу по выбраному полю... чего-то не получается...

подскажите где не так плз...

SoulBurn
16.10.2008, 19:50
Вобщем помог всемогущий гугл...
Подключил вот этот (http://blogwm.ru/wp-content/uploads/2008/09/sorttable.zip) ява-скрипт этой:
$GLOBALS['TSFE']->additionalHeaderData['test'] .= '<script type="text/javascript" src="'.t3lib_extMgm::siteRelPath('test').'res/scripts/sorttable.js"></script>'.chr(10);
командой (дописывает строчку в хедер)... Делать в PHP нет времени :(

ВАЖНО!!!
<table class="sortable"> обязательно sortable, иначе скрипт не будет работать (разбираться в Яве лень :p)

З.Ы. И всё-таки хотельсь бы увидеть решение на PHP (не дай Бог клиент захочет раскрасить строки зеброй :))

З.З.Ы. Исходники немного поменялись поэтому выкладываю снова

class.tx_test_pi1.php
<?php
require_once(PATH_tslib.'class.tslib_pibase.php');

class tx_test_pi1 extends tslib_pibase {
var $prefixId = 'tx_test_pi1'; // Same as class name
var $scriptRelPath = 'pi1/class.tx_test_pi1.php'; // Path to this script relative to the extension dir.
var $extKey = 'test'; // The extension key.
var $pi_checkCHash = true;
var $eventUid;

function main($content,$conf) {

$this->conf=$conf;
$this->pi_setPiVarDefaults();
$this->pi_loadLL();
$this->pi_USER_INT_obj=1;

$content = $this->displayList();

return $this->pi_wrapInBaseClass($content);
}


function displayList($content,$conf) {

$this->templateCode = $this->cObj->fileResource('EXT:test/res/test_template.html');
$GLOBALS['TSFE']->additionalHeaderData['test'] .= '<script type="text/javascript" src="'.t3lib_extMgm::siteRelPath('test').'res/scripts/sorttable.js"></script>'.chr(10);
$GLOBALS['TSFE']->additionalHeaderData['test'] .= '<link rel="stylesheet" type="text/css" href="'.t3lib_extMgm::siteRelPath('test').'res/css/test.css" />'.chr(10);

$template = array();
$template['total'] = $this->cObj->getSubpart($this->templateCode,'###TEST_TEMPLATE###');
$template['singlerow'] = $this->cObj->getSubpart($template['total'],'###SINGLEROW###');
$template['row'] = $this->cObj->getSubpart($template['singlerow'],'###ITEM###');
$template['row_alt'] = $this->cObj->getSubpart($template['singlerow'],'###ITEM_ALT###');

$marker = array();
$marker['###TEST_HID###'] = $this->pi_getLL('id');
$marker['###TEST_HNAME###'] = $this->pi_getLL('name');
$marker['###TEST_HLNAME###']= $this->pi_getLL('lname');
$marker['###TEST_HAGE###'] = $this->pi_getLL('age');
$marker['###TEST_ACTION###'] = $this->pi_getPageLink($GLOBALS[TSFE]->id);

$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,name,last_name,age','tx_test _db','');

$switch_row = 0;
while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {

$marker['###TEST_ID###'] = $row['uid'];
$marker['###TEST_NAME###'] = $row['name'];
$marker['###TEST_LNAME###'] = $row['last_name'];
$marker['###TEST_AGE###'] = $row['age'];

>substituteMarkerArrayCached($template['row'], $marker);

}
$subpartArray['###SINGLEROW###'] = $content_item;

$content .= $this->cObj->substituteMarkerArrayCached($template['total'],$marker,$subpartArray);

return $content;
}
}

if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/test/pi1/class.tx_test_pi1.php']) {
include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/test/pi1/class.tx_test_pi1.php']);
}

?>
test_template.html
<!-- ###TEST_TEMPLATE### begin -->
<table class="sortable">
<thead>
<tr class="table-header">
<th>###TEST_HID###</th>
<th>###TEST_HNAME###</th>
<th>###TEST_HLNAME###</th>
<th>###TEST_HAGE###</th>
</tr>
</thead>
<tbody>
<!-- ###SINGLEROW### -->
<!-- ###ITEM### -->
<tr class="table-body1">
<th>###TEST_ID###</th>
<th>###TEST_NAME###</th>
<th><!-- ###LINK### -->###TEST_LNAME###<!-- ###LINK### --></th>
<th>###TEST_AGE###</th>
</tr>
<!-- ###ITEM### -->
<!-- ###ITEM_ALT### -->
<tr class="table-body2">
<th>###TEST_ID###</th>
<th>###TEST_NAME###</th>
<th><!-- ###LINK### -->###TEST_LNAME###<!-- ###LINK### --></th>
<th>###TEST_AGE###</th>
</tr>
<!-- ###ITEM_ALT### -->
<!-- ###SINGLEROW### -->
</tbody>
<tfoot>
<tr class="table-footer">
<th><a href="index.php?id=132&amp;tx_julleevents_pi1[showUid]=1&amp;cHash=6739979ac8" >Click</th>
<th></th>
<th></th>
<th></th>
</tr>
</tfoot>
</table>
<!-- ###TEST_TEMPLATE### end -->
</body>
</html>