Thursday, June 2, 2011

jQuery Autocomplete With Columns

My current job has shifted dramatically from doing Windows application development to web development (and then back again, and then back to web, etc.). With that change has come a crash course in JavaScript & jQuery programming.

One of the things I ran into was putting columns in jQuery's autocomplete. I found a pretty good answer on StackOverflow but I wanted to avoid using tables if I could. After some experimentation and a little more research I found an implementation that works.

I'd love to show an example of what I'm talking about within this post but Blogger's javascript support is... lacking (here it is on my Skydrive if you're truly curious or blogger butchers the code in this post). Since my JavaScript-fu isn't strong, I welcome any comments on doing this better but anyway, here's the code I came up with:

With the associated html:

It's assumed that the jquery, jquery ui and jquery ui css files are pulled in on the page.

The key to getting the columns to work lies in the _renderItem method override. The autocomplete is going to give you an unordered list tag and an item from the source. What you want to return is the unordered list with whatever list items to add added on.


The pitfalls I ran into were how the items should be formatted:
  1. The information needs to be wrapped in an anchor tag to play nice with the jquery ui stuff, then you can start wrapping things in divs (I'm definitely no CSS expert so if it's done wrong, I'd love to know how it should be done).
  2. I needed to make sure to set the width on the parent div so that nothing would wrap to another line.
  3. Each column had its own div with a set width floated left except for the last one. Whenever I tried to mess with that, the highlighting in the drop-down would be messed up.
  4. There's a space at the end of each column in case a field was null/empty. This prevents other nonsense that would happen with the drop-down highlighting.

Sunday, April 3, 2011

Interview Observations

There have been some big events that have happened recently that have affected me professionally:
  1. World of Warcraft: Cataclysm was released (or National Call In Sick Week).
  2. Burned out on World of Warcraft and quit.
  3. Changed employers.
I could talk for ages about items one & two but this is a programming blog so I better talk about number three.

Looking for work was an interesting journey because I went from participating in & conducting interviews to being the one interviewed (and then back again to participating in interviews). From all these experiences I have learned a few things that I wanted to share with others that may be looking for development work.

Preparation


Keep Up


First and foremost, keep yourself marketable before you need a new job. It's one thing to look for a job because you're bored or feel like your current job has run it's course but it's quite another if you're laid off/fired. If you wait until then to start sharpening your skills, it's kind of too late.

It'd be neat to be able to say that you know how to effectively program in C#, Ruby, Java, etc. in all their respective frameworks but that's quite a feat even if you don't have a family to support or other responsibilities. What you can do is do a little side project here or there in your favorite language and maybe target an interesting framework you don't necessarily use at work. Breaking that project out in an interview can show your potential employer that you love your craft.

Know The Jargon


Though it's not required, it's extremely helpful to know some of the newer concepts being thrown around the development community. And hey, why not learn what they mean why you're at it? It's never fun getting called out on a subject you said you knew, but don't really. Here are some of my favorites:

Know The Movers & Shakers


Another optional thing to look into, but very valuable nonetheless, is to know the important people in your industry. And not only know who they are, find out what they're working on next. This can be as simple as following a blog or a Twitter account. Some of my favorites include Scott Hanselman, Oren Eini and Uncle Bob (there are a ton more).

The Interview


So you've done all your preparation and got an interview lined up. If you well and truly know your stuff, the interview shouldn't be much trouble. In fact, if you're prepared, interviewing can be fun, just keep a few things in mind:
  • Take a shower - I've had people come in that I can smell. If the interviewer can smell you, you're not getting the job.
  • Don't lie - Either in person or on your resume, you will get called out on it, you will look like an ass, you won't get the job.
  • If you don't know, you don't know - If you're asked something you don't know, say you don't know. It may or may not be a deal-breaker for the interviewer but it's always a deal-breaker if you lie and get caught in it.
  • Show enthusiasm - If you act like you don't care about the job now, what's to say you're going to care after you're hired?
  • Be confident, but not cocky - I actually had to learn this the hard way. You might "know in your heart" that you're an above-average developer. You may think you're the best candidate for the job. But you know what? There will always be a better programmer than you and the best programmers are always aware of this. People that are cocky come across as someone that will be hard to work with and will poison a team's morale. Humility is key!

When Things Don't Work Out


You've done your homework, the interview went well (well, you're pretty sure anyway) and yet you get that call/email saying "thanks, but no thanks." It happens. It's happened to me and maybe I made it happen to someone else. Maybe you didn't say a magic word the interviewer wanted to hear. Maybe another candidate out-awesomed you. Maybe the interviewer just didn't like your face. You might find out why but most likely you won't. Just try to make sure that you're more prepared next time and stop being a cocky shit during the interview!

When Things Do Work Out


After you've nailed that new job, keep in mind what you had to go through to get it. Don't let yourself get complacent. Stay informed of new technologies coming out. Get involved with the development community on and offline. Be grateful that you have a job doing something you love but always be ready for when you need to move on.