Monday, September 17, 2012

KendoUI AutoComplete and JSON for the RESTofus

Like Scott... I've oft had disdain for the web dev' experience.

Started programming in '67, and haven't missed a day since. ArpaNet was exciting, but Berner's-Lee ideas opened up a pandora's box to be land-Netscape-d, and we're still trimming the bushes.

So, I've not been all that anti-MS over the years, but they certainly have a habit of trying one's patience, don't they. The MS approach to the web is no exception: "do it this way. No, wait... that way is bad... try this."

"ActiveX, COM, DCOM, COM+, CLR, .NET, Web-sockets, not yet" it all starts to sound like a Billy Joel song. Isn't it funny how parts of 'Razor' markup resemble classic .asp? Kinda makes you long for the Scott McNealy vision all over again. Man, the transition from AWT to Swing seemed orderly by comparison.

So... way back in the dark ages of 2002 ASP.NET with ViewState seemed like a good idea. Yeah... that was the ticket. We can think like desktop-developers, not worry so much about state-preservation, and concentrate on the LOB app's biz-rules. Nice. Until ViewState became larger than the page, and every thing that a poor user did caused churn and grunts as latency destroyed patience and the number of postbacks caused epileptic fits.

So we used lots of server-side widgets (gotta love those grids) to help. Things got slightly better... but, there was no way that I could not shudder at the thought of the poor users sitting in the office, forced to enter data into a system that was 2-4x slower than it should be. And.. after trimming Session and ViewState, and using more JS to reduce round-trips, we still ended up with users hating the experience, going into epileptic shock from the latency blues. Remember the promise of 'SmartNavigation'? Never worked well, right?

So, we all started to take a hard look at AJAX. Loading data asynch'ly client-side... wicked pissah. Telerik had some fantastic examples and widgets embracing the paradigm. For me, the JS door cracked open a little more; getelementByID and InnerHTML became good friends.

And then John Resig did us all a huge deed. jQuery saved the day. All of a sudden, JS was almost a real language. And... we started to escape from the bondage of the mighty MS 'long and winding' road-map.

OK... I've been typing too long, and I really wanted to talk about my latest KendoUI experiments.

So, have YOU tried to get the KendoUI AutoComplete to do its thing for you? Do YOU have it working with a RESTful JSON remote datasource? Well... I must say, it was more than a bit of pain, and it wasn't exactly a 'restful' project dalliance. but... maan.. it rocks.

Feast your eyes on this and behold the beauty:

$("#patSearch").kendoAutoComplete({
minLength: 2,
placeholder: "(Initials, DOB, MRN)",
suggest: true,
animation: { open:
{ effects: "fadeIn",
duration: 300,
show: true
}
},
dataTextField: "LastName",
dataSource: this.patients,
template:
"<span class='patSearchRow'> ${data.LastName.trim()},${data.FirstName}-${data.DOBString}-&nbspMRN:${data.MRN}-${data.ID}</span>",
select: function (e) {
if (e.item !== null) {
var theitem = this.dataItem(e.item.index());
session.setPatientInContext(theitem);
}
}
})
autoComplete = $("#patSearch").data("kendoAutoComplete");
autoComplete.list.width(400);
autoComplete.list.addClass("patSearchRow")


I'm starting to like Kendo, and love it's harmony with (and the ubiquity of) jQuery. It's not just that KendoUI rocks... it's the attitude of the whole JS-library community. There's alot of great people putting tons of effort into JS. And soooo many cool things we can now do for our enslaved users.

It's not exactly easy yet... but we're getting there.

More later... the bees are a-callin'. Time to put more sugar-water on the hive; winter's coming.

Long live ECMAscript !

1 comment:

  1. cool stuff! have you guys seen our hero Anders' little project at Microsoft? http://www.typescriptlang.org/

    ReplyDelete