tablesorter jquery plugin?

General Chat, Comments
Post Reply
User avatar
cbsarge
Posts: 195
Joined: Mon Sep 14, 2015 3:20 pm

tablesorter jquery plugin?

Post 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/
User avatar
KyleMassacre
Posts: 573
Joined: Wed Nov 27, 2013 12:42 pm

Re: tablesorter jquery plugin?

Post by KyleMassacre »

Hmm, would make for a nice little plugin
User avatar
cbsarge
Posts: 195
Joined: Mon Sep 14, 2015 3:20 pm

Re: tablesorter jquery plugin?

Post 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... :|
User avatar
KyleMassacre
Posts: 573
Joined: Wed Nov 27, 2013 12:42 pm

Re: tablesorter jquery plugin?

Post 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']
User avatar
cbsarge
Posts: 195
Joined: Mon Sep 14, 2015 3:20 pm

Re: tablesorter jquery plugin?

Post by cbsarge »

Shouldn't just including a link to the Jquery library in the head of the main.php accomplish the same thing?
User avatar
KyleMassacre
Posts: 573
Joined: Wed Nov 27, 2013 12:42 pm

Re: tablesorter jquery plugin?

Post 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
User avatar
cbsarge
Posts: 195
Joined: Mon Sep 14, 2015 3:20 pm

Re: tablesorter jquery plugin?

Post 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
?>
User avatar
cbsarge
Posts: 195
Joined: Mon Sep 14, 2015 3:20 pm

Re: tablesorter jquery plugin?

Post 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>";
User avatar
KyleMassacre
Posts: 573
Joined: Wed Nov 27, 2013 12:42 pm

Re: tablesorter jquery plugin?

Post 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
User avatar
cbsarge
Posts: 195
Joined: Mon Sep 14, 2015 3:20 pm

Re: tablesorter jquery plugin?

Post 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.
Post Reply

Return to “General”