Results 1 to 2 of 2

Thread: List items with custom icons

  1. #1
    Sencha User
    Join Date
    Apr 2012
    Vote Rating

    Default List items with custom icons

    You can set custom icon to every item in List (Ext.dataview.List) or Dataview according to its type. I have used sprite PNG-image with custom icons. We will take advantages of CSS and templates.
    For this you need to do next steps
    1) to your items in Data, array of records, which you pass to the List, you should add iconCls field, where you should put custom CSS class containing right icon for each item. And set all this info to your list via store and model
                Ext.define('ListModel', {
                    extend: '',
                    config: {
                        fields: [/*your fields*/,
                            {name: 'iconCls', type: 'string'}
                for (var i = 0, ln = records.length; i < ln; i++) {
                                            /*set fields values*/,
                        iconCls: /*custom CSS class for icon*/
                var store = Ext.create('', {
                    model: 'ListModel',
                    data: data
                list = Ext.create('Ext.Dataview.List', {
                    store: store,
                    iconsCls: 'iconCls',
                    iconsBaseCls: 'x-list-icons'
    2) In List you should pre-config your Template for item (ColumnName - is name of display field)
    Base CSS class is used in context of sprite image implementation.
        initConfig: function(config) {
            var iconsCls = this.getIconsCls();
            var iconsBaseCls = this.getIconsBaseCls();
            iconsBaseCls = iconsBaseCls ? iconsBaseCls : '';
            var itemTpl = new Ext.XTemplate(
                '<div class="' + iconsBaseCls +' {' + iconsCls + '}">' ,
                {' + ColumnName + '}</div>' 
    And there you are. Every item will set its own CSS class according to its iconCls field. I show some CSS example, which fits the code above.
    .x-list .x-list-item .x-list-icons {
        padding-left: 32px !important;
    .x-list .x-list-item .x-list-icons::before {
        background-image: url('../images/icons.png');
        background-repeat: no-repeat;
        width: 32px;
        height: 32px;
        content: "";
        position: absolute;
        left: 0;
    .x-list-icons.x-icon1::before {
        background-position: 0px 0px;
    .x-list-icons.x-icon2::before {
        background-position: -36px 0px;
    .x-list-icons.x-icon3::before {
        background-position: -72px 0px;

  2. #2
    Sencha Premium User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Gainesville, FL
    Vote Rating


    Thanks for sharing how you accomplished something!
    Mitchell Simoens @LikelyMitch
    Modus Create, Senior Frontend Engineer
    Need any sort of Ext JS help? Modus Create is here to help!

    Check out my GitHub:

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts