Tuesday, April 2, 2013

Jquery Mobile - Split button listview

    Today we will be taking a look at a listview example where we can include 2 clickable items instead of the usual 1 clickable item. In all the listview examples that we have seen till date, we have had only 1 clickable item per list, i.e. only 1 anchor tag included within the li tag. We will now take a look at an example where we will see, how to add 2 clickable items in the same list.

    In case where there are more than 1 possible action per list item, a split button can be used to offer two independently clickable items - the list item and a small icon in the far right. To make a split list item, we simple need to include a second link inside the li tag and JQM framework will do the rest for you. It will add a vertical divider line, style the link as an icon-only button and set the title attribute of the link to the text of the link for accessibility as you can see in the result section in the jsFiddle below.



    You can set the icon on the extreme right by specifying the data-split-icon attribute on the listview with an icon name you want. The default icon is "arrow-r" but can be configured with the splitIcon listview options. I have used the "star" icon in the above example. By adding a data-icon attribute to the list item, you can set individual icons for each split. The theme swatch color of the split button defaults to "b" but can be set by specifying a swatch letter with the data-split-theme attribute at the list level as I have used the "c". For individual splits, you can apply the swatches with data-theme attribute at the link level.

    The icon that we have used for the split need not be from the JQM default icon set. We can have our own icon and we will see how to customize the icon on the listview in subsequent examples. Stay tuned for more examples on Jquery Mobile. Hope you have followed this one. Drop a comment in case you have any issues regarding this code sample and I would be happy to help.

If this post has helped you, leave a comment or show your love by liking the Spatial Unlimited Facebook page. You could even consider buying me a coffe! Till next time; happy coding!