Welcome, Guest. Please login or register.
Did you miss your activation email?
May 26, 2012, 06:05:59 AM

Login with username, password and session length
Search:     Advanced search
Wollen Sie dem WebsiteBaker Team beitreten?
Nähere Informationen finden Sie unter hier und auf unserer neuen Webseite.
155533 Posts in 21713 Topics by 7739 Members
Latest Member: audillino
* Home Help Search Login Register
Pages: [1]   Go Down
Print
Author Topic: Implementing sortable table javascript to a simple wb table-page  (Read 1775 times)
Vidar

Offline Offline

Posts: 36


« on: March 16, 2010, 12:39:30 PM »

Hey,

I'm looking for some help! I need a sortable table for my site. I found the SorTable at AMASP but I couldn't get it to work the way I want.

I need a table where the first cell contains a wb-link. So the first word is a link to another wb-site. This is very easy to create at wysiwyg editor in wb backend. But Is there a way to make this table sortable?

I googled around and found plenty of links about table sorting with javasrcript. I tried the tutorial from this site: http://yoast.com/articles/sortable-table/tutorial/ . This is what I did:

1. I created a simple table with wysiwyg

2. I copied the sortable.js to root of my site

3. I switched to source mode on the wysiwyg editor and inserted this:
Code:
<table class="sortable" id="sortable_example">

4. I inserted this to my templates index.php head section:
Code:
<script type="text/javascript" src="sortable.js"></script>

5. I copied this to the css

Code:
.odd {
 background-color: #ddd;
}
.even {
 background-color: #fff;
}

So I just followed the instructions on that site, but without any luck.
I know this isn't a wb's problem but I would really appreciate your help! I don't think that this is a hard job for someone who actually knows about these things Smiley I'm just learning by doing!
Logged
pcwacht
AddOn Development
*
Offline Offline

Posts: 2859



WWW
« Reply #1 on: March 16, 2010, 01:17:56 PM »

watch point 4

Make sure the JS is loaded!
<script src="<?php echo TEMPLATE_DIR; ?>/sortabel.js" type=text/javascript></script>
put the js in your template directory.

Have fun,
John

PS Make sure to test this first WITHOUT links. Most javascript sortable's can't handel links properly
I think this one can if you put the link in an unsortable column.
« Last Edit: March 16, 2010, 01:20:51 PM by pcwacht » Logged

http://www.ictwacht.nl = Dutch ICT info
http://www.pcwacht.nl = My first
both still work in progress, since years.....
Vidar

Offline Offline

Posts: 36


« Reply #2 on: March 16, 2010, 01:36:26 PM »

I knew I could count on your expertice!

Thank you John, now it works as I had hoped.  cool

Now it's just a matter of some css tweaking.

Logged
Vidar

Offline Offline

Posts: 36


« Reply #3 on: April 23, 2010, 07:26:19 PM »

Hey,

the table still works, even with links.

Is there a way to set a default sorting? I' typed all the data on the table in a random order so it would be nice to set some row as a default sorting option.

Thanks in advance!
Logged
pcwacht
AddOn Development
*
Offline Offline

Posts: 2859



WWW
« Reply #4 on: April 23, 2010, 07:28:18 PM »

Seems like there is no default sort.
Can't find it.

John
Logged

http://www.ictwacht.nl = Dutch ICT info
http://www.pcwacht.nl = My first
both still work in progress, since years.....
Vidar

Offline Offline

Posts: 36


« Reply #5 on: April 24, 2010, 07:33:32 AM »

Well that's a shame. Thanks for a quick reply though!
Logged
mr-fan

Offline Offline

Posts: 1556


WWW
« Reply #6 on: April 24, 2010, 01:42:48 PM »

hi there you could use the new jQueryAdmin Modul to get your own jQuery Tablesorter running and reuse it easy on every installation or website....

jQueryAdmin:
http://www.websitebakers.com/pages/libs/jqueryadmin.php

some Plugins for examples how to use it:
http://www.websitebakers.com/pages/libs/jqueryadmin/jquery-library.php

unfortunally there is only a german documentation how to create a plugin for now.....
http://www.webing.de/webbird/websitebaker/JQueryAdminPlugins

the threat is english:
http://www.websitebaker2.org/forum/index.php/topic,17705.0.html

and here one of my favorite jQuery table sorters:
http://tablesorter.com/docs/index.html

many real good features and easy to use...

have fun
martin
Logged

 
Vidar

Offline Offline

Posts: 36


« Reply #7 on: April 25, 2010, 07:26:13 AM »

I've used a lot of community driven software over the years but WebsiteBaker has definately the best people!

Thanks for your links mr-fan, I'll check those out when I have the time.
Logged
Vidar

Offline Offline

Posts: 36


« Reply #8 on: July 01, 2010, 10:26:58 AM »

mr-fan, I tried the tablesorter you suggested but I haven't been able to make it work. I don't really understarnd jquery and the whole jquery-admin consept, but I gave it a shot.

Since I don't know any german I used the allmighty googletranslate to get something out of the make your own plugin -instructions: http://www.webing.de/webbird/websitebaker/JQueryAdminPlugins

1. I downloaded the jquery-tablesorter http://tablesorter.com/docs/index.html, extracted it and uploaded the whole thing to my server: wb/modules/jqueryadmin/plugins/tablesorter

2. I tried to create the default.preset file according to the instructions:
Code:
<script src  = type = "{WB_URL}/modules/jqueryadmin/jquery-1.4.2/jquery-1.4.2.min.js" "text/javascript" charset = "utf-8"> </ script>
<link rel = "stylesheet" href = "{WB_URL}/modules/jqueryadmin/plugins/tablesorter/themes/blue/style.css" type = "text/css" media = "screen" charset = "utf-8" / > <Link rel = "stylesheet" href = "() WB_URL / modules/jqueryadmin/plugins/tablesorter/themes/blue/style.css"  type = "text / css" media = "screen" charset = "utf-8 "/>
<script src = "{WB_URL}/modules/jqueryadmin/plugins/tablesorter/jquery.tablesorter.min.js" type = "text/javascript" charset = "utf-8" > </script> <script src = type = "{WB_URL}/modules/jqueryadmin/plugins/tablesorter/jquery.tablesorter.min.js" text/javascript" charset = "utf-8"> </ script>
<!-- position: body --> <! - Position: body ->

3. At the end of the file there is the part of the actual code to load the plugin, so I copied the code from http://tablesorter.com/docs/index.html:
Code:
$(document).ready(function()
    {
        $("#myTable").tablesorter();
    }
);
   

4. So my default.preset file lookes like this:
Code:
<script src  = type = "{WB_URL}/modules/jqueryadmin/jquery-1.4.2/jquery-1.4.2.min.js" "text/javascript" charset = "utf-8"> </ script>
<link rel = "stylesheet" href = "{WB_URL}/modules/jqueryadmin/plugins/tablesorter/themes/blue/style.css" type = "text/css" media = "screen" charset = "utf-8" / > <Link rel = "stylesheet" href = "() WB_URL / modules/jqueryadmin/plugins/tablesorter/themes/blue/style.css"  type = "text / css" media = "screen" charset = "utf-8 "/>
<script src = "{WB_URL}/modules/jqueryadmin/plugins/tablesorter/jquery.tablesorter.min.js" type = "text/javascript" charset = "utf-8" > </script> <script src = type = "{WB_URL}/modules/jqueryadmin/plugins/tablesorter/jquery.tablesorter.min.js" text/javascript" charset = "utf-8"> </ script>
<!-- position: body --> <! - Position: body ->

<script type = "text/javascript" charset = "utf-8" > <script type = "text/javascript" charset = "utf-8">
$(document).ready(function()
    {
        $("#myTable").tablesorter();
    }
);
    </ Script>

5. I created a standard html table page and gave it a id of myTable (as in the example).

6. I used the dropled to load the plugin: [[jQueryInclude?plugin=tablesorter]]

But nothing happens...I haven't included tablesorter js files on the template, cause i thought that the point of jqueryadmin is to avoid that.

Could anyone lend a hand?
Logged
mr-fan

Offline Offline

Posts: 1556


WWW
« Reply #9 on: July 01, 2010, 11:33:55 AM »

hi vidar,

the technique behind jQueryAdmin is maybe complicate from the start...but it handels jQuery Plugins and other Javascripts perfect and for non Programmers very easy by clicking the wanted scripts.....so but our/your Problem is

=> create a own Preset/Plugin to use it with the jQueryAdmin....

1. you on a good way

2. script calls was false ->jquery itself would be loaded automatically and the other ones aren't correct!

3. your steps basicly where allright just like it is the most time....cusive bugs and some copy&paste  bugs...Wink

so here is a quik and dirty Plugin for jQueryAdmin - im very busy at the time so i don't have the time to create a little help file or check deeper if it works...

* corrected script calls
* added pager.js plugin for tablesorter
* added blue and green theme
* checked short if files are loaded correct - don't set up a test table or something....

please install it via jqueryAdmin and check if it works!

If not we will figure it out that it do what we/you want! Smiley

Would be nice if we get it - if you could make a little help html like in the other plugins for other users then we put it on AMASP and share?

best regards
martin
Logged

 
Vidar

Offline Offline

Posts: 36


« Reply #10 on: July 02, 2010, 06:21:32 AM »

Thank you for your reply!

Basicly, it works! The testtable that i created really got sortable.

But: no css seems to be loaded. Should i add the css to my templates css, or...? (my current tablesorter's css stuff is part of my templates css).

Should I activate the pager plugin somehow?

If we get this thing sorted out I'll be hapy to create the html file, I should have some time on the weekend.
Logged
mr-fan

Offline Offline

Posts: 1556


WWW
« Reply #11 on: July 02, 2010, 06:43:05 AM »

hi,

no CSS is loaded by jQueryAdmin look at the sourcecode!

have you cleared the browser cache?

I did a short test and it works like it should on my localtestenvironmen t...

have you a link (if it is a online page)?

regards
martin
Logged

 
Vidar

Offline Offline

Posts: 36


« Reply #12 on: July 02, 2010, 06:51:33 AM »

the test page is an hidden online page w ww.kenike.fi/wb/pages/testi.php

So I should integrate the blue sortable-template to my wb template? 'Cause that I can do as soon as I get to my home machine Smiley (currently at work)

Thanks for your help!
« Last Edit: July 02, 2010, 11:12:06 AM by Vidar » Logged
erpe

Offline Offline

Posts: 2077


WWW
« Reply #13 on: July 02, 2010, 11:14:16 AM »

I took the plugin from mr-fan, added the help pages and now it is available on AMASP.

It can also be seen on jQueryPlugin Showroom.

rgds

erpe
Logged

Vidar

Offline Offline

Posts: 36


« Reply #14 on: July 02, 2010, 12:07:56 PM »

Thanks Erpe,

installed your version and I'll try to check the css tomorrow. Atleast for now there's no style loaded.

But how can I enable the included pager?
Logged
erpe

Offline Offline

Posts: 2077


WWW
« Reply #15 on: July 02, 2010, 12:18:30 PM »

Quote
Atleast for now there's no style loaded
Then there must be something wrong with your installation.
As Martin said the css will be loaded automatically by using jQueryAdmin:
http://jquery.websitebakers.com/plugins/others/tablesorter.php
(see generated html-code)

For enabling other things see homepage of the script:
http://tablesorter.com/docs/index.html

rgds

erpe

Logged

Vidar

Offline Offline

Posts: 36


« Reply #16 on: July 03, 2010, 07:27:12 AM »

yep, once again user-fault: the class-attribute wasn't correct. Style is now loaded as it should.

Sorry to keep bugging you guys, but where should I input those extra options for the script: pager etc.

the code from the scripts site is:
Code:
$(document).ready(function() {
    $("table")
    .tablesorter({widthFixed: true, widgets: ['zebra']})
    .tablesorterPager({container: $("#pager")});
});

But i can't seem to put it in the default.preset or tablesorter.jquery files in a way that it would work... Any ideas?

Thank you so much!
Logged
Vidar

Offline Offline

Posts: 36


« Reply #17 on: July 04, 2010, 07:37:43 AM »

I can't believe this is so hard.

Sorter works when default.preset and tablesorter.jquery have the default code:
Code:
$(document).ready(function()
    {
        $("#referenssitaulukko").tablesorter();
    }
);
</script>
where referenssitaulukko is the id of the table.

My table has the same id and class=tablesorter.

But how to add the pager?

1. I took the example pager-div from this page http://www.novell.com/communities/node/8797/jquery-tablesorter-pagination-and-sorting-made-simple :
Code:
<div id="pager" class="pager">
<form>
<img src="images/first.png" class="first"/>
<img src="images/prev.png" class="prev"/>
<input type="text" class="pagedisplay"/>
<img src="images/next.png" class="next"/>
<img src="images/last.png" class="last"/>
<select class="pagesize">
<option value="">>LIMIT</option>
<option value="2">2 per page</option>
<option value="5">5 per page</option>
<option value="10">10 per page</option>

</select>
</form>
</div>
I added this to the bottom of my page.

2. Same page has also the correct code to load pager:
Code:
$(document).ready(function()
    {
        $("#insured_list")
.tablesorter({widthFixed: true, widgets: ['zebra']})
.tablesorterPager({container: $("#pager")});
    }
);
</script>

and the Script authors webpage has this:
Code:
$(document).ready(function() {
    $("table")
    .tablesorter({widthFixed: true, widgets: ['zebra']})
    .tablesorterPager({container: $("#pager")});
});

I've tried them both. I corrected the table id (table=referenssitaulukko) and then tried to replace the default code from the default.preset and/or tablesorter.jquery with this, but it afterwards sorting dosen't work.

I guess to a person familiar with jquery this isn't a hard thing to do, but to a total amateur this seems to be...
The question is: where should I put those codes? To the default.preset, to tablesorter.jquery, both or somewhere else? This script has also a lot of extra options but I have now idea where to employ them...

Any help/tips are greatly appreciated!
Logged
erpe

Offline Offline

Posts: 2077


WWW
« Reply #18 on: July 04, 2010, 12:21:38 PM »

I don't know where your error is.
I took the code from demo-page,  modified the css-file, included the images and modified the code in tablesorter.jquery to the code from demopage (see genrated code)
http://www.rvb.bplaced.net/pages/tablesorter_pager.php

rgds

erpe

Maybe you mixed code from different sides?

Logged

Vidar

Offline Offline

Posts: 36


« Reply #19 on: July 07, 2010, 10:18:21 AM »

Well, I still don't know where the error was but it's working now! Thanks erpe!

I tried this over and over again. It started working when I copied everything from your test site and edited tablesorter.jquery.

Thanks!
Logged
erpe

Offline Offline

Posts: 2077


WWW
« Reply #20 on: July 07, 2010, 10:41:51 AM »

Quote
It started working when I copied everything from your test site and edited tablesorter.jquery.
That's why I did this page  wink

rgds

erpe
Logged

Pages: [1]   Go Up
Print
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!