Sunday, March 22, 2009

How We Got Our Cats

We had a great method for getting our cats. We lost our one cat to old age about 2 years ago. So, off to Orphans of the Storm (lincolnshire, methinks). Into a room with 300 cats we 5 marched: Beck and I, and the 3 kids who were having a very very bad day. That is, they were squirelly, loud, obnoxious, moving too fast, chasing, screaming, etc.

We had 7 or 8 cats approach us. One, with us now and named Sirius Black because he's SERIOUSLY black, is a hunk of old bunker-buster weight-lifting hunka-hunka-burning-cat. That day, he crawled into Beck's lap and started purring despite the fact that 2 other cats were ON TOP of him, fighting. This is the mark of a winner cat.

Second was Luna Lovegood, who played with the kids despite them being less than polite, but was very lithe and coped well with the situation. We have since learned she's a theoretical physicist of a cat (I would say 'rocket scientist' but that's not as much of an achievement anymore). We have a YouTube video of her opening a door.

We have doors that have a thumb-push-down latch in our older home, and one closed to keep the upstairs separate. This was great. I'm mildly allergic, so can't sleep with cats, but I can stand it as long as I don't pet them and rub my eyes or breathe in their fur. So, life is good with a dividing line, the door. But, Luna started appearing upstairs on our bed in the middle of the night, and I was sure I closed the door at night.

She learned to stand on the stove, balance on one foot, tap the latch and pull at the same time to open the door. Here is the YouTube link.

We went out that weekend and bought a new door and mounted it in a different doorway, having to change the hinge locations and do lots of carpentry. I got to have some fun streching my skillset.

RECOMMENDED: Use Tung Oil. We did the rather bland looking pine door in about 10 coats of Tung oil with a light sanding using extra fine steel wool between. Now it looks Fantastic, like we paid tons for this expensive solid wood door with a fancy finish. True, the tung oil cost more than the door, but it was worth it.

So, to sum up, don't get your cats with kids on a good day. Get them on a bad day, and the ones that self-select to approach you are the keepers.

Wednesday, March 11, 2009

Working with JQuery Tablesorter Parser Input Fields

I've recently had to deal with JQuery's tablesorter. the trouble was, it had a problem sorting form input fields in columns. The columns sorted fine when they were static text, but when each column was a form entry field of <input type="text" ...> it wouldn't sort. this is because it was trying to sort the HTML of "<input ..." instead of the field value.

The solution to this took a little googleing and a bit of creative coding. My first solution was to use a regex to recognize the value="aaaa" and replace it to have the parser work on that text. The yucky factor was big.

Instead, I found the concept of using a val function on the text. This ended up being two parsers, because one of my input fields was a numeric value.

Here's the text:

$.tablesorter.addParser({
id: "textbox_text",
is: function(s) {
return false;
},
format: function(s) {
return $($.trim(s)).val().toLowerCase();
},
type: "text"
});

$.tablesorter.addParser({
id: "textbox_numeric",
is: function(s) {
return false;
},
format: function(s) {
return $($.trim(s)).val().toLowerCase();
},
type: "numeric"
});

$.tablesorter.addParser({
id: "checkbox_parser",
is: function(s) {
return false;
},
format: function(s) {
ret = $($.trim(s)).attr('checked');
return ret
},
type: "numeric"
});

$(document).ready(function()
{
$("#docReqTable").tablesorter(
{ widgets: ['zebra'],
sortColumn: 1,
sortClassAsc: 'headerSortUp', // class name for ascending sorting action to header
sortClassDesc: 'headerSortDown', // class name for descending sorting action to header
headerClass: 'header', // class name for headers (th's)
stripingRowClass: ['even','odd'], // class names for striping supplyed as a array.
stripRowsOnStartUp: true,
sortList: [[1, 0]],
headers: {
0 : { sorter : 'checkbox_parser' },
1 : { sorter : 'textbox_text' },
3 : { sorter : 'checkbox_parser' },
4 : { sorter : 'textbox_numeric' },
5 : { sorter : 'textbox_numeric' },
},
debug: true,
});
});


I'm having trouble now because I type in the input fields, and then click on a header to re-sort the data, and it doesn't sort to the top. That is, dynamically updating the values in the table doesn't allow a sorton operation in JQuery tablesorter to recognize the new values.

We already had a method to change the mouse pointer to a 'hand' when it mouseover'd the table header, so it looked like a clickable link there (a good visual clue to the user that the table really is sortable).

So, I tried adding a couple of methods I found online to the mouseover code to see if they would update the cache and allow resort based on the dynamically changed values inside the textbox. I even put some code in the tablesorter.js file for reSort_A and reSort_B that tried some things, to no avail.

The code for that is:

...
th onMouseOver="setPointerHand(this);" onMouseOut="setPointerDefault(this);" class="{sorter: 'text'}"
...
function setPointerHand(method)
{
document.body.style.cursor = 'hand';
$(docReqTable).trigger("appendCache");
$(docReqTable).trigger("update");
$(docReqTable).trigger('reSort_B');
$(docReqTable).trigger('applyWidgets');
return false;
}

function setPointerDefault(method)
{
document.body.style.cursor = 'default';
$(docReqTable).trigger("appendCache");
$(docReqTable).trigger("update");
//$(docReqTable).trigger("log", "doing stuff");
$(docReqTable).trigger('reSort_B');
$(docReqTable).trigger('applyWidgets');
return false;
}



That's as far as I've gotten. If anyone has clues for how to make the update / re-sort work well, please reply on this blog or otherwise post it!