Skip to content

October 16, 2011

Enhance ExtJS Ticker with Store support

by Joe Kuan

I need a ExtJS ticker and I found someone posted the code in the sencha forum which has an online demo. However, I need a number of extra features which are not supported. So again I have modified the code. Couple of the features are inspired by Mioplanet’s news ticker. Here are the main features:

  • option for ExtJS Store object
  • visually enhance with color labels
  • ticker pauses when mouse hovers over
  • support categorised message type such as: Warning, Info
  • click event handler support for messages


You can download the code here.


For usage example, see ticker.html in the github


In order to support Store class, when the ticker retrieves messages from the server side, the messages are stored until the current ticking messages are scrolled to the end. Then the new arrived messages are formatted and displayed.

To create a Ticker object with a Store object, simply do:

var ticker = new Ext.ux.Ticker({
  id: 'ticker',
  width: 450,
  autoHeight: true,
  direction: 'left',
  store: new{
    url: './ticker.json'
    fields: [ 'id', 'time', 'type', 'message' ],
    autoLoad: false

In this implementation, the JsonStore returns each ticker message contains id, time, type and message fields.

The id field is the id of the message which is particular useful if you need to bind further click action to the message. The type field is the message type for grouping the messages into a category. In my example, I use type values as ‘warn’ or ‘info’ and display these categories with specific color tags before the messages. Users can modify these type values for their own applications. The time field is in unit of seconds of unix time.

If you need to modify the Ticker class for different data schema, then overwrite the default setReloadStore and setMessages methods.

The method setReloadStore is to format the Store records into ticker message objects when the store’s load method is called.

// Define your own if on how you want to group message differently
setReloadStore: function() {
  // Format into ticker messages when the records arrived'load', function(store, records, opts) {
    // List of messages for each category
    var warnMsg = [], infoMsg = [];
    for (var i = 0; i < records.length; i++) {
      var rec = records[i];
      // Format unix time into datetime
      var dt = Date.parseDate(, "U");
      // Grouping 'warning' type messages
      if ( == 1) {
        warnMsg.push({ id:, msg: dt.format('G:i:s') + ' ' + + '. ' });
      // Grouping 'info' type messages
      else if ( == 2) {
        infoMsg.push({ id:, msg: dt.format('G:i:s') + ' ' + + '. ' });

    this.reloadStore = false;

    // show messages now or wait for messages scroll to the end
    this.updateMessages({ warn: warnMsg, info: infoMsg });
  }, this);

The setMessages method is to 1) convert the message objects into HTML elements with appropriate CSS classes defined in ticker.css, 2) if click event handler is defined, bind it to each ticker message.

// If msgs is string, then just update element
// If msgs is an object with warn or info fields, then add some color tags
setMessages: function(msgs) {

  // Setup warning messages are defined
  if (msgs.warn && msgs.warn.length) {
    // Create a bold font colored tag leading all the warning messages
    this.els.push(this.contentEl.createChild({ tag: 'font', html:  "Warning", cls: 'x-ticker-warn' }));
      // Put the msgHandlers into scope of click method
      function(item) {
        item.msgHandlers = this.msgHandlers;
        // Create the message element
        var el = this.contentEl.createChild({ tag: 'span', html: item.msg, cls: 'x-ticker-message' });
        // Bind the message click event handler
        el.on('click', function() {
          if (this.msgHandlers && this.msgHandlers.warn) {
            this.msgHandlers.warn(, this.msg);
        }, item);

The bindMsgHandler method allows you to bind specific event handler on clicking certain type of message. The event handler is expected to accept id and message parameters.

var msgHandler = function(id, message) {
  Ext.Msg.alert('Info', "You click ticker msg id: " + id + ", message " + message);

ticker.bindMsgHandler('info', msgHandler);
ticker.bindMsgHandler('warn', msgHandler);

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Note: HTML is allowed. Your email address will never be published.

Subscribe to comments

%d bloggers like this: