/* =================================
** ==== Simple Table Controller ====
** =================================
**
**
** With Pure JavaScript ..
**
**
** No Libraries or Frameworks needed!
**
**
** fb.com/bastony
**
*/
// get the table element
var $table = document.getElementById("myTable"),
// number of rows per page
$n = 15,
// number of rows of the table
$rowCount = $table.rows.length,
// get the first cell's tag name (in the first row)
$firstRow = $table.rows[0].firstElementChild.tagName,
// boolean var to check if table has a head row
$hasHead = ($firstRow === "TH"),
// an array to hold each row
$tr = [],
// loop counters, to start count from rows[1] (2nd row) if the first row has a head tag
$i,$ii,$j = ($hasHead)?1:0,
// holds the first row if it has a (
) & nothing if (
)
$th = ($hasHead?$table.rows[(0)].outerHTML:"");
// count the number of pages
var $pageCount = Math.ceil($rowCount / $n);
// if we had one page only, then we have nothing to do ..
if ($pageCount > 1) {
// assign each row outHTML (tag name & innerHTML) to the array
for ($i = $j,$ii = 0; $i < $rowCount; $i++, $ii++)
$tr[$ii] = $table.rows[$i].outerHTML;
// create a div block to hold the buttons
$table.insertAdjacentHTML("afterend","";
for ($i=1; $i<=$pCount;$i++)
$buttons += "";
$buttons += "";
return $buttons;
}
function filterText()
{
var rex = new RegExp($('#filterText').val());
if(rex =="/all/"){clearFilter()}else{
$('.content').hide();
$('.content').filter(function() {
return rex.test($(this).text());
}).show();
}
}
function clearFilter()
{
$('.filterText').val('');
$('.content').show();
}