It’s the Web, just Kwwika

The real-time web. Delivered. 
Filed under

JavaScript

 

Dynamically sorting a table with jQuery tablesorter plugin

I'm in the middle of building our user dashboard and have been using jQuery extensively to add a rich feel to the UI. Since our focus is data it's not surprising that I have some tables in our UI. I decided I should add some sorting functionality to the table for a couple of reasons; Iare dynamically adding rows to the table when new data is created and I also want Kwwika users to be able to sort tables to help them find data.

Rather than write some JavaScript from scratch, and was the case for many years, I automatically did a search for jQuery sort plugins and I managed to compile a list of few that seem to work or at least have potential. I eventually decided to go with tablesorter since it's been around for a while, is pretty stable, the code isn't too complex for what shouldn't be a complex thing and the styling was also nice an basic and could easily be customised.

We got the manual sorting functionality up and running really easily and I then added a couple of calls to first let the plugin know the data had been updated and then to tell the plugin to sort the table. Here's the code in its simplest format.

Tablesorter-demo

When you click the add button eventually the table.trigger("sorton", [[[1,0]]]) is called. The first parameter is the method to be called and the second parameter is something the documentation refers to as a sort list (important note: this parameter should be an array of parameters as defined in the jQuery trigger docs - this got us for a bit):

An array of instructions for per-column sorting and direction in the format: [[columnIndex, sortDirection], ... ] where columnIndex is a zero-based index for your columns left-to-right and sortDirection is 0 for Ascending and 1 for Descending. A valid argument that sorts ascending first by column 1 and then column 2 looks like: [[0,0],[1,0]]

But it doesn't work!

Those of you who have worked with JavaScript for a while will probably be aware that it's single-threaded (for getting Web Workers) and that queued scripts only get a chance to execute either when one finishes or a setTimeout is called. My hunch was that something within the "update" trigger call had pushed some execution into a setTimeout call so to work around this I needed to do the same for my "sorton" trigger call to make sure that all other processed had finished execution and the DOM and the tablesorter plugin were in the state I wanted to be in.

setTimeout(function()
{
var sorting = [[1,0]];
table.trigger("sorton", [sorting]);
}, 0);

It worked!

So, you'll be pleased to hear that the data tables within the Kwwika User Dashboard are nice and dynamic ready for users to find and organise their data.

Demo 

Here's a link to a working demo.

Here's a full working listing of some example code:

Filed under  //   JavaScript   UI   User Dashboard   jQuery   jQuery tablesorter plugin  
Posted by email 

Comments [0]

How to dynamically load JavaScript and CSS files

One of the requirements of the Opta Sports real-time Cricket widget (blog post | Opta Sports live cricket scores page) was that including the widget should be as simple as possible. One way to keep things simple is to only need to include one script tag which dynamically includes all required JavaScript and CSS files. We'd outsourced some of the widget development to Matador Digital and we passed this requirement on to them. They came up with a nifty bit of JavaScript that met exactly these requirements.

This example is tied to loading the files we required for our widget, including the Kwwika JavaScript API, but it wouldn't be at all difficult to take this code and create a small generic JavaScript and CSS loading utility function. The require function is generic and could easily be used as a solution to load any JavaScript or CSS file.

There are of course other solutions available:
A quick search will also come up with a number of solutions.

If you find any other solutions please get in touch and we'll update this post.

Filed under  //   CSS   JavaScript   Utilities  
Posted by email 

Comments [0]

Kwwika support for webOS

We've got a potential client interested in using Kwwika on HP webOS so we've been working with them to test the Kwwika JavaScript library on a platform that we've not been directly targeting. After a problem glitch with the 64bit webOS DK (mainly JVM and PATH problems) we got the 32bit one up and running and the a webOS emulator fired up. From there Palm have created a really nifty web IDE called Ares. Ares communicates with the webOS emulator, which runs on Virtual Box, via the web browser Java plugin and it allows you to launch the application and debug it. This works surprisingly well.

We came across three problems with the Kwwika JavaScript API where we'd made assumptions that the library would be running within a web browser. We fixed this by stepping through the code with Ares debugger and soon we were connected, logged in, subscribing to data and publishing data.

The code is super-simple since it's just a normal HTML page:

And our application didn't have any UI but you can see from the log at the bottom of this screenshot that the Kwwika JavaScript library is working with webOS as expected.
Webos_ares

Filed under  //   HP   JavaScript   Palm   webOS  
Posted by email 

Comments [0]

Plotting tweets in real-time using Smoothie Charts and Kwwika

I noticed a tweet today about real-time JavaScript charts and couldn't resist having a play. The charts are call Smoothie Charts and have been developed by Joe Walnes. You can read the blog post where he announced the release of them here.

The demos that I've seen don't use real-time data so I thought I would create a small demo using real-time tweets being pushed through Kwwika. I updated the Kwwika TweetStreamer component (which I must get around to putting in GitHub) to push through updates from some popular hashtags including #nowplaying, #news, #tech and a few others and then wrote a bit of code to count the number of tweet updates over an interval and push that value into a Smoothie chart. The result looks like this (Smoothie charts use Canvas so only work in some browsers. I've tested this demo in Firefox and Chrome):

Smoothie-charts-kwwika-demo

You can see the Smoothie Twitter Real-Time Charting demo using Kwwika here: http://kwwika.com/Standalone/Demos/javascript-examples/smoothie-twitter-charting/

I've got the Smoothie chart showing the number of updates for each twitter hashtag, a table showing the count and a list of the tweets at the bottom.

The code is in GitHub so feel free to fork/download and have a play yourself. You can run the code on http://localhost but in order to get the code to work on your own website you'll need to register with Kwwika and get in touch to let us know you want access to the real-time Twitter hashtag topics.

Update: We found a bug in the Smoothie library which Joe Walnes promptly fixed.

One thing we've noticed is that the Smoothie chart stops working and throws an exception and as yet we've not been able to work out what the problem is due to lack of time. It's probably something to do with not getting any updated values in a TimeSeries. This is what the exception look like in Firebug:

Smoothie-error

If anybody can work out what the problem is please let us know. Failing that we'll look into it when we can.

Filed under  //   javascript   real-time data   real-time push   smoothie charts   twitter  
Posted by email 

Comments [3]

Kwwika JavaScript API "How to..."

We've just posted a couple of "How to.." examples on the Kwwika Wiki. The first shows how to use a simple HTML <form> and publish the values through Kwwika

Publish

The seconds shows how to display those real-time updates on a web page.

Subscribe

If you are using the Kwwika JavaScript API and would like to know "How to..." achieve something then please get in touch. The likelihood is that if you would like to know how to do something then either somebody else does or will do in the future.

Filed under  //   How to   JavaScript   JavaScript API   Real-Time Push  
Posted by email 

Comments [1]

Want to try out the Kwwika API but don't want to register?

We're try to get more and more people using Kwwika and we feel that registering is maybe a barrier to entry. So, we've decided to give everybody access to our service. The only caveat is that we've just enabled access from your local development machine, assuming you can run a local application from http://localhost.

So, if you want to try out the Kwwika JavaScript API but don't want to register (yet), then go ahead. There's a topic that you can subscribe and publish to named /KWWIKA/SANDBOX.

You can even start building a Kwwika World Cup 2010 Real-Time Push Web App because we've give http://localhost access to the data you need to use to enter the competition:

/OPTA/WC2010/TEAMLIVE
/KWWIKA/TWITTER/SEARCHES/WC2010/*

If you need help getting started you can of course get in touch or start by going through our Real-Time Web Workshop. This workshop contains a presentation, a set of exercises and all the files (download) that you need to go through the exercises. This even in includes and executable webserver to run on windows, a webserver app to run on Mac and a python webserver to run on Linux (or any other python enabled machine).

So, why not start developing using Kwwika now. And if you like it, or are just damn good at developing real-time push apps, why not register and enter our World Cup 2010 competition.

Filed under  //   API   JavaScript   Real-Time Data   Real-Time Push   Real-Time Web  
Posted by email 

Comments [0]

Kwwika Silverlight API - Chat Example

This video shows a chat application built using the Kwwika JavaScript API and a chat application built using the Kwwika Silverlight API. Both applications can communicate with each other in real-time using the Kwwika service.

We'll release the source code for both applications in the very near future.

Filed under  //   API   Chat   Example   JavaScript   Kwwika   Real Time Web   Real-Time Data   Silverlight  
Posted by email 

Comments [0]