• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2665
  • Last Modified:

JQuery Mobile - Listview slow

Hi,

I have a listview with many records taken from a mysql table, there are about 4000. When I search it all happens very slowly.
Doing research on google I found a solution https://github.com/jquery/jquery-mobile/blob/4ffb0a5f33ecf7a0df5caa1ed69dc02b57126195/js/jquery.mobile.listview.filter.js

I tested it and it works really well, the only problem I have is that displays two search input.
Can anyone help me?

Simple page:
<!DOCTYPE html> 
<html> 
	<head> 
	<title>Elenco Clienti</title> 

	<meta name="viewport" content="width=device-width, initial-scale=1"> 
	<link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
	<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
	<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
</head>



<script type="text/javascript">

/*
* jQuery Mobile Framework : "listview" filter extension
* Copyright (c) jQuery Project
* Dual licensed under the MIT or GPL Version 2 licenses.
* http://jquery.org/license
*/
(function($, undefined ) {

$.mobile.listview.prototype.options.filter = false;
$.mobile.listview.prototype.options.filterPlaceholder = "Filter items...";

$( ":jqmData(role='listview')" ).live( "listviewcreate", function() {
	var list = $( this ),
		listview = list.data( "listview" );

	if ( !listview.options.filter ) {
		return;
	}

	var wrapper = $( "<form>", { "class": "ui-listview-filter ui-bar-c", "role": "search" } ),

		search = $( "<input>", {
				placeholder: listview.options.filterPlaceholder
			})
			.attr( "data-" + $.mobile.ns + "type", "search" )
			.bind( "keyup change", function() {

				var val = this.value.toLowerCase(),
					listItems=null,
					lastval = $( this ).jqmData('lastval')+"";

				//change val as lastval for next execution  
				$(this).jqmData( 'lastval' , val );

				change = val.replace( new RegExp( "^" + lastval ) , "" );

				if( val.length < lastval.length || change.length != ( val.length - lastval.length ) ){

					//removed chars or pasted something totaly different, check all items
					listItems = list.children();
				} else {

					//only chars added, not removed, only use visible subset
					listItems = list.children( ':not(.ui-screen-hidden)' );
				}

				if ( val ) {

					// This handles hiding regular rows without the text we search for
					// and any list dividers without regular rows shown under it
					var item, 
						childItems = false,                        
						itemtext="";

					for (var i = listItems.length; i >= 0; i--) {
						item = $( listItems[i] );
						itemtext = item.jqmData( 'filtertext' ) || item.text();

						if ( item.is( "li:jqmData(role=list-divider)" ) ) {

							item.toggleClass( 'ui-filter-hidequeue' , !childItems );

							// New bucket!
							childItems = false;

						} else if ( itemtext.toLowerCase().indexOf( val ) === -1) {

							//mark to be hidden
							item.toggleClass( 'ui-filter-hidequeue' , true );
						} else {

							// There's a shown item in the bucket
							childItems = true;
						}
					}

					// show items, not marked to be hidden
					listItems
						.filter( ':not(.ui-filter-hidequeue)' )
						.toggleClass('ui-screen-hidden',false);

					// hide items, marked to be hidden
					listItems
						.filter( '.ui-filter-hidequeue' )
						.toggleClass('ui-screen-hidden',true)
						.toggleClass( 'ui-filter-hidequeue' , false );

				}else{

					//filtervalue is empty => show all
					listItems.toggleClass('ui-screen-hidden',false);
				}
			})
			.appendTo( wrapper )
			.textinput();

	if ($( this ).jqmData( "inset" ) ) {
		wrapper.addClass( "ui-listview-filter-inset" );
	}

	wrapper.insertBefore( list );
});

})( jQuery );

</script>

<body>

<div data-role="page">

	<div data-role="header">
		<h1>My Title</h1>
	</div><!-- /header -->

	<div data-role="content">	
		<p>Hello world</p>
		<ul data-role="listview" add data-filter="true">
			
	<li><a href="acura.html">Acura</a></li>
	<li><a href="audi.html">Audi</a></li>
	<li><a href="bmw.html">BMW</a></li>
</ul>
	</div><!-- /content -->

</div><!-- /page -->	

</body>
</html>

Open in new window

0
danz67
Asked:
danz67
  • 2
1 Solution
 
nap0leonCommented:
Try removing this line.
wrapper.insertBefore( list );

Open in new window

0
 
danz67Author Commented:
I resolved,
just add id name.

(function($, custom-format-listview )

Open in new window


<div data-role="content">
	    <ul id="custom-format-listview" data-role="listview" data-filter="true" data-filter-placeholder="Cerca...">

Open in new window


this is pretty good, but I do not think it is the best solution. Is there a way to show other records after a query with limit?
0
 
danz67Author Commented:
Best Solution find in the web
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now