I’m trying to include the jQuery plugin tablesorter in my Yii view for “turning a standard HTML table with THEAD and TBODY tags into a sortable table without page refreshes”.
I am aware that CGridView would be a more elegant version to do this in Yii but I am mainly interested in getting the jQuery plugin to work. As of now, the table is not sortable although other jQuery functions (e.g., a pop-up window or a toggle button) work.
Any ideas what I am doing wrong? This is my view:
<?php
Yii::app()->clientScript->registerCoreScript('http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js');
Yii::app()->clientScript->registerScript('buttonscript',"
$('button').click(function(){
$('p').slideToggle();
});
",CClientScript::POS_READY);
Yii::app()->clientScript->registerScriptFile('/jquery.tablesorter.js');
Yii::app()->clientScript->registerScript('tablescript',"
$(document).ready(function()
{
$('#myTable1').tablesorter();
}
);
",CClientScript::POS_READY);
?>
<?php
echo "<p id='paragraph1'>This is a paragraph.</p>";
echo "<button id='button1'>Toggle between slide up and slide down for a p element</button>";
echo "<table id='myTable1' class='tablesorter'>
<thead>
<tr>
<th>Last Name</th>
<th>First Name</th>
</tr>
</thead>
<tbody>
<tr>
<td>Smith</td>
<td>John</td>
</tr>
<tr>
<td>Jones</td>
<td>Martha</td>
</tr>
<tr>
<td>Noble</td>
<td>Donna</td>
</tr>
<tr>
<td>Smith</td>
<td>Mickey</td>
</tr>
</tbody>
</table>";
?>
Edit: Must be a path problem. When I hotlink directly to jquery.tablesorter.js, it works fine. Question can be closed.