Book Image

PHP Ajax Cookbook

Book Image

PHP Ajax Cookbook

Overview of this book

Table of Contents (16 chapters)
PHP Ajax Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Sorting and filtering data


Usually, the best place for sorting and filtering data is the database. But, sometimes, we need to work with the given data on the client side only. For example, filtering a simple contact list or sorting a small data grid. In this task, we will learn how to filter and sort data on the client side.

Getting ready

We will need the jQuery library:

<script src="js/jquery-1.4.4.js"></script>

We will also need a sample of data in JSON format from json/developers.json:

[{
  "fullname"      : "Hefin Jones",
  "contactlocation"  : "St David's, Wales",
  "labels"      : "MS SQL, DBA"
},
...
{
  "fullname"      : "Raphaël Gabbarelli",
  "contactlocation"  : "Rome, Italy",
  "labels"      : ".Net(C#), Windows Phone 7"
}]

How to do it...

  1. In the beginning, we will build the HTML code with searchPlaceHolder and datalist, as shown in the following code snippet:

    <div class="searchPlaceHolder">
      <label for="search" style="">Type to Search: </label>
      <div...