Page 1 of 1

tablesorter jquery plugin?

Posted: Wed Oct 28, 2015 9:01 pm
by cbsarge
Has anyone successfully integrated the jquery tablesorter plugin to the NWE engine? IT would be a nice addition to the search players screen if I could sort by the different values.

http://tablesorter.com/docs/

Re: tablesorter jquery plugin?

Posted: Wed Oct 28, 2015 11:17 pm
by KyleMassacre
Hmm, would make for a nice little plugin

Re: tablesorter jquery plugin?

Posted: Thu Oct 29, 2015 12:31 pm
by cbsarge
So far all of my attempts have simply resulted in the following displaying in the Chrome console:

Code: Select all

Uncaught TypeError: $(...).tablesorter is not a function
If I don't include a link to a jquery library with the link to the tablesorter library it complains it doesn't know what $ means. If I do include it (listed first of course) it resultsin the above error. I've tried calling it from the main.php file in the template folder as well as the index.php file in the root and tried adding lines in the common.php file.

I'm stumped... :|

Re: tablesorter jquery plugin?

Posted: Thu Oct 29, 2015 12:37 pm
by KyleMassacre
Jquery must be included first which JQ is already included in the engine some variables that you should take advantage of is $content. There are a couple array keys here that you should be able to use:
$content['footer'] and $content['footerScript']

Re: tablesorter jquery plugin?

Posted: Thu Oct 29, 2015 12:58 pm
by cbsarge
Shouldn't just including a link to the Jquery library in the head of the main.php accomplish the same thing?

Re: tablesorter jquery plugin?

Posted: Thu Oct 29, 2015 1:09 pm
by KyleMassacre
In theory, yes. In reality meh! The engine is quite dynamic meaning everything is interchangeable through the module. Jquery shouldn't be loaded into the head of the main.php file if I recall correctly unless it is a custom template and done incorrectly. I believe it's loaded through the Ajax::IncludeLib() method which hot links to the Google hosted cdn library. Having 2 jquery libraries tends to break jquery as well.

So what you should do is:

Code: Select all

global $content;
$content['footer'] .= "path/to/tablesorter.js";
$content['footerScript'] .= "$('#table').tablesorter();";//this is your table sorter jquery call
I could have the array keys backwards and you may require the <script>tags for both array injections.

Also check your index.php file for correct implementations

Re: tablesorter jquery plugin?

Posted: Thu Oct 29, 2015 1:17 pm
by cbsarge
...and would those lines go in the head of the main.php in the template? There was already a call to $content['header'] in there.

Like this?

Code: Select all

<?php echo $content['header']; 
echo $content['footer'] .= "path/to/tablesorter.js";
echo $content['footerScript'] .= "$('#myTable').tablesorter();";//this is your table sorter jquery call
?>

Re: tablesorter jquery plugin?

Posted: Thu Oct 29, 2015 2:52 pm
by cbsarge
So where should this go?

Code: Select all

$content['footerScript'] .= "<script src='{$webBaseDir}js/jquery.tablesorter.js'></script>";
$content['footerScript'] .= "<script>\$('#myTable').tablesorter();</script>";

Re: tablesorter jquery plugin?

Posted: Thu Oct 29, 2015 3:32 pm
by KyleMassacre
cbsarge wrote:So where should this go?

Code: Select all

$content['footerScript'] .= "<script src='{$webBaseDir}js/jquery.tablesorter.js'></script>";
$content['footerScript'] .= "<script>\$('#myTable').tablesorter();</script>";
That would go in your content.php file

Re: tablesorter jquery plugin?

Posted: Thu Oct 29, 2015 4:40 pm
by cbsarge
ugh...

Thanks Kyle but, apparently I still need some hand-holding. Let me know if you decide to take a look at this and if you figure it out. I'm admitting defeat for now.