
- jQuery Mobile Tutorial
- jQuery Mobile - Home
- jQuery Mobile - Overview
- jQuery Mobile - Setup
- jQuery Mobile - Pages
- jQuery Mobile - Icons
- jQuery Mobile - Transitions
- jQuery Mobile - Layouts
- jQuery Mobile - Widgets
- jQuery Mobile - Events
- jQuery Mobile - Forms
- jQuery Mobile - Themes
- jQuery Mobile - CSS Classes
- jQuery Mobile - Data Attributes
- jQuery Mobile Useful Resources
- jQuery Mobile - Interview Questions
- jQuery Mobile - Quick Guide
- jQuery Mobile - Useful Resources
- jQuery Mobile - Discussion
jQuery Mobile - Listview Autodivider Selector
Description
The first character of the list item is used by the autodivider plugin by default. The autodividersSelector option helps to return a different string.
Example
Following example demonstrates the use of listview autodivider selector in the jQuery Mobile.
<!DOCTYPE html> <html> <head> <meta name = "viewport" content = "width = device-width, initial-scale = 1"> <link rel = "stylesheet" href = "https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css"> <script src = "https://code.jquery.com/jquery-1.11.3.min.js"></script> <script src = "https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script> <script> $(document).ready(function() { var dateList = $("#selector"); for(var i = 0, len = selector.length; i<len; i++) { dateList.append("<li>"+selector[i]+"</li>"); } dateList.listview ({ autodividersSelector: function ( li ) { var d = new Date(li.text()); return (d.getMonth()+1)+ "/" + d.getDate() + "/" + d.getFullYear(); } }).listview("refresh"); }); </script> </head> <body> <ul data-role = "listview" data-inset = "true" id = "selector" data-autodividers = "true"> <li><a href = "#">01/01/2016 09:15:00</a></li> <li><a href = "#">01/05/2016 10:00:00</a></li> <li><a href = "#">01/05/2016 12:45:00</a></li> <li><a href = "#">01/12/2016 12:00:00</a></li> <li><a href = "#">01/12/2016 18:30:00</a></li> <li><a href = "#">01/16/2016 14:00:00</a></li> </ul> </body> </html>
Output
Let's carry out the following steps to see how the above code works −
Save the above html code as listview_autodivider_selector.html file in your server root folder.
Open this HTML file as http://localhost/listview_autodivider_selector.html and the following output will be displayed.
jquery_mobile_widgets.htm
Advertisements