Some updates on reordering items with jQuery

If you follow my blog at all, you know I have a keen interest in being able to reorder items in a list and then record that change in order in a database using JavaScript, specifically with the jQuery UI Sortables component. Here's some things I've learned recently regarding the topic:

Reordering Nested Lists

In my last project, I created a tool that allowed my clients to rearrange nested lists of articles and article categories using the jQuery UI Sortables component and the techniques I demonstrated in an earlier blog post.

My clients were very excited about the tool when they saw it in the prototype, but they ran into some difficulty when they tried to use it themselves during the final testing. They found it hard to place an item at either end of a list block because there were no visual cues outlining the borders of the list.

It was also nearly impossible for them to move an item around in the top-most list: if they tried to place it in between sibling items or at the end of the list, the item would almost always get dropped at the end of whatever sublist came at the end of the sibling item above.

Finally, the scrollable <div> element containing the nested lists would not scroll to match the drag movement of the cursor, so if they needed to move an item from one end of the nested lists to the other, the item would have to moved in steps.

I solved all of these problems by abandoning the drag-and-drop technique and replacing it with a version of my "click-to-click move" technique. So now when they need to move an item, they click on an icon associated with each item (hidden until needed), and target <div>s are created above and below each item:

Image of move targets in my last project

They then just click on the target for the place they want the item moved to, and the item is "moved" and the targets are removed (technically, the item is cloned, the clone is put in the new position, and the original item is deleted).

They like the "click-to-click move" version a lot better, so perhaps that's a better means of reordering items when using nested lists. But I recently discovered jTree, a brand-new jQuery plugin someone wrote specifically for sorting nested lists using drag-and-drop. I tried out the demo for it, and it has visual cues to help you position items in the right list, but it does flicker a bit at times. Still, I might play with it the next time I have to deal with nested lists again.

Reordering Table Rows

Lists are nice, but they don't cut it when each item is really a collection of separate items: that's when you need a table. In my current project, I needed a way to reorder the rows in my table as a means of letting the user reorder the data records. The jQuery UI Sortables component, however, does not work on table rows.

I tried to create a pseudo-table by using <div>s within each <li> item to evenly space the data fields in each row. I got it working and looking slightly less than ugly in FireFox, but it didn't fare so well in IE.

I then went browsing through the jQuery UI discussion board on Google Groups and found a post that mentioned a plugin for sorting/rearranging table rows.

It's called TableDnD, and it's a slightly different approach to the challenge. When you click on a row and drag it, there is no drag outline and no gradual movement: if you move up far enough, the content of the row you're dragging and the row above it quickly switch places, and vice-versa if you move downward. It highlights the moving row as you move it so you can keep track of what's happening. The movement is very smooth and you can go as fast as you like.

The only drawbacks I'm aware of so far is that the dragging action will not trigger the scroll bar if you're trying to drag the row beyond the visual limit of the window or scrollable container (much like my original nested list tool), and someone pointed out to me that if you fill all of the cells in a row with other DOM elements such that you cannot click on any of the cells themselves, you won't be able to grab the row and move it. That's not a problem your table cells just contain text, but it's something to keep in mind if you plan on formatting the text with <span> tags or providing input boxes for the user to edtit the cell data.

Online, Flex-Powered Express Version of Photoshop Available!

Saw the news about this on some of the blog feeds this morning:

https://www.photoshop.com/express/landing.html

I only had time to take the test drive (no sign-up required) and briefly mess with one of the stock image, but still...Wow.

Problem: No Drag-and-Drop On The iPhone/iPod Touch. Solution: Click-To-Click Move

As I mentioned in an earlier blog post, the drag-and-drop functions provided by various JavaScript libraries (jQuery, YUI, etc.) won't work in the iPhone/iPod Touch Safari web browser because the dragging gesture is used for scrolling around the web page.

That's a big problem for those of us who use drag-and-drop in our web applications to allow our users to reorder the items in a list, but I've come up with an alternative method for rearranging items using the jQuery JavaScript library that works on the iPhone/iPod browser as well as regular browsers. I call it the "Click-to-Click Move" method (CTCM).

[More]

New YouTube API= Flex Apps To Manage YouTube Videos?

YouTube announced the release of a new set of APIs today that (from what I've read so far) allow you to use YouTube as a web service. You can use API calls to log into YouTube, upload videos, list videos, edit the metadata about videos, and more.

Flex is obviously well-positioned to make use of these new APIs, given that the videos themselves are done in Flash. I wonder what apps will come out of this new development?

Here's the link to the main YouTube API page:

http://code.google.com/apis/youtube/overview.html

If You Don't Follow RIA News, You Must Be a TWiT

I just finished listening to the latest "This Week in Tech" (TWiT) podcast on my way home from work tonight.

I'm a regular listener of TWiT. Even though I'm aware of most of their news items prior to hearing it from them, I like some of the personalities on the show and their discussions are generally interesting. But I have one big problem with TWiT: they never talk about RIA (Rich Internet Application) technology. Oh, they might say the word "Flash" or "Flex" in regard to some specific product or service, and maybe say a sentence or two about AJAX, but that's as far as it ever goes. Maybe they think their audience is mostly end-users who don't care, but that doesn't stop them from talking about stuff that only geeks would truly care about, so I don't think it's a valid excuse.

I thought this week might be different. With all of the press coverage over the release of AIR this week, and with all the subsequent articles hyping the RIA struggle between Microsoft and Adobe, Silverlight vs. AIR (even though it's not an accurate comparision)...surely the TWiT panel couldn't ignore the topic this week.

Sure they could.

What got me even more frustrated was the way it WASN'T mentioned. Just over 4 minutes into what was an 87-minute podcast, host Leo Laporte notes they have a large roundtable group and "absolutely nothing to talk about." Not usually a good sign for the rest of the podcast.

After discussing about two news stories and a discussion about having another option for listening to podcasts besides via iTunes, the discussion turned to a comparison between the Twitter and Pownce messaging systems. I got hopeful again: Pownce provides an AIR-powered desktop application, so maybe the discussion would cause the AIR release to come up. One panelist mentioned that the Pownce API had been updated last week, and I thought "Maybe they were waiting on the release of AIR to release that new API" (I have no idea if the events were related).

So I shouted (I kid you not) at my iPod, while driving in my car, at the pre-recorded voice of someone who could not possibly hear me: "Say maybe it was because of AIR! Mention AIR! SAY ITS NAME!"

Yeah, well, that didn't work.

I'm not a fanboy of AIR, or Flex, or any of the other RIA technologies (though I do use AJAX reasonably often). I like whatever gets the job done in the most reasonable way. I wouldn't be upset if they made fun of any of those technologies, or questioned their usefulness, or whatever: I listen to them for their opinions, whether I agree with them or not.

But to not say anything: that's pathetic. RIAs are out there and gaining a presence, whether good or bad. I can't see how you can ignore them by mistake.

Near the end of the podcast, regular panelist John Dvorak mocked the use of Twitter because at the end of the day, it didn't put $5 in his pocket, and a few minutes later someone on Twitter apparently offered to send him $5.

Hey, John, I'll send you $5 if you can get the TWiT panel to discuss RIA technology. It would be worth it at 10x the price.

BlogCFC was created by Raymond Camden. This blog is running version 5.1.004.