sorting dynamic tables with jquery and tablesorter

Posted in jquery on October 27th, 2009 by paul – 1 Comment

I have a page in an application where the user can move names from one column (table) to another.

I have a bunch of js that removes the selected row from table a and adds it to table b.

Everytime I change one of the tables I want to sort the tables.

The syntax is below, if only for my own reference as it took me ages to get it just right. I need to write a custom sorter as I need to sort on the second word (i.e. surname). But anyway, the following is in a function that gets called when a row is moved between tables…

function sort_table(table){
   $(table).tablesorter();
   $(table).trigger("update");
   var sorting = [[0,0]];
   // sort on the first column
   $(table).trigger("sorton",[sorting]);
}

There’s nothing particularily novel here, all available around the net. The call to

$(table).trigger("update");

is there as I found that when I moved a row over to the right column and then sorted the left column the row appeared to be still in that table. This is because tablesorter uses a cache of some sort. Calling .trigger(“update”) forces it to rebuild the cache. Or something like that…

problems updating ssl certificate on cpanel

Posted in cpanel on October 14th, 2009 by paul – Be the first to comment

Today I had to install a renewed ssl cert for a client on their cpanel server.

cPanel has a pretty good interface for managing ssl certs, but it doesn’t always go to plan (so, perhaps not so good…).

I logged in to the clients cpanel account and installed the new certificate (the contents of the .crt file).

On submitting this, everything appeared to work ok, but the website was still showing the expired certificate. So the new certificate was being installed but apache was still using the old one.

After much head scratching I tried doing the install via WHM, i.e. the ‘root’ user interface.

I used the “Install a SSL Certificate and Setup the Domain” page. I pasted in the ssl cert, and this meant WHM autimatically picked up the domain, the key and ca bundle. Submitting this form seemed to work, i.e. apache started serving up the correct certificate.

Bit of a pain…

jQuery tablesorter plugin and dates

Posted in jquery on September 21st, 2009 by paul – Be the first to comment

I recently discovered the exellent tablesorter jquery plugin for sorting tables of data. It works very well and saved a lot of time having to write server side sorting code.

I did hit a small snag with dates of the format “12 Aug 2008″. The default sorter seemed to be sorting on the day part of the date and ignoring everything else.

In the end I had to set the sorter for these columns as the isoDate sorter which works perfectly, once I set the dateFormat to “uk”.

eg

<script type="text/javascript" charset="utf-8">
 $(document).ready(function()
 {
   $("#pupils_table").tablesorter({
                                   headers: {
                                             4: {
                                                 sorter:'isoDate'
                                                 }
                                   },
                                   dateFormat: "uk"
                                   });
 }
 );
</script>

error undefined method `use_transactional_fixtures=’ for Test::Unit::TestCase:Class

Posted in rails on September 16th, 2009 by paul – Be the first to comment

When running some tests today I hit the error message: undefined method `use_transactional_fixtures=’ for Test::Unit::TestCase:Class

Searching for this came up with numerous results.

The way to fix this is to change the class in test/test_helper.rb from Test::Unit::TestCase to ActiveSupport::TestCase

Tests should run properly now.

This is while using rails 2.3.2 on OS X.

IE8 compatibility mode and cellpadding, cellspacing

Posted in Uncategorized on September 11th, 2009 by paul – Be the first to comment

I recently had a problem whereby a table with a dynamic number of rows had a space above it that I couldn’t explain initially.

The table was in a modal style dialogue with no markup above it before the start of the div. However, the gap betwen the top of the table and the top of the div was variable, depending on the number of rows in the table. The greater the number of rows, the bigger the gap; so clearly the table rows where the problem. I had set margin and padding to zero but that didn’t do it.

Eventually I tried setting the cellpadding and cellspacing to zero, and that fixed the problem.

This may be very obvious to markup experts but I hadn’t seen this before (or if I had I’d forgotten, hence this reminder).

Only a problem in IE8 in compatibility mode.

stop rails writting fieldwitherrors on error

Posted in Uncategorized on September 1st, 2009 by paul – Be the first to comment

It is usually quite handy to have rails wrap one’s form fields in a div to indicate which ones have an error but sometimes it can be a real pain.

Alex Vollmer shows you how to stop rails adding these extra divs to your form fields.

git: send changed files to github

Posted in Uncategorized on August 20th, 2009 by paul – Be the first to comment

git push origin will send any files one has commited locally to the mast server (eg github).
That is a simplistic explanation however.
git status is handy as it will give you an idea of the, umm, status of the files you are working with…

using custom routes to pass parameters to a method

Posted in rails on August 3rd, 2009 by paul – Comments Off

In an application I am working on I needed to pass the ID of an object to the new action of a controller. This ID was the id of an object the new object would be linked to.

Now creating the link as /controller/object_id called the show method (as this is a standard restful route). What I wanted to do was do something like /controller/new/object_id , but that isn’t a valid route.

What I had to do was create a custom route to make this work.

So in my routes.rb file I added a line like this:

map.new_object '/controller/new/:object_id', :controller => 'controller', :action => 'new'

now in my new action I can access the passed in id as params[:object_id]

crontab: command not found

Posted in Uncategorized on July 2nd, 2009 by paul – Be the first to comment

On a centos 5.3  vps I got recently I found that crontab was not installed.

On typing crontab -e to edit root’s crontab I got the error:

crontab: command not found

It seemed odd that this was not installed. Anyway, it took me a few moments to work out what package I needed to install.

yum install vixie-cron

there you go.

bind9 secondary on ubuntu

Posted in Uncategorized on July 2nd, 2009 by paul – Be the first to comment

I needed to setup a new secondary name server as one of mine went down  and I didn’t know if it was every going to come back.

So In installed bind9 on a ubuntu server as per the instructions on this page

One problem I ran into though was a permission denied error when the new secondary server tried to transfer zones from the primary server.

This was fixed by changing the owner of /var/bind from root to bind

The next time the transfer happened it worked just fine.