Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

jQuery EasyUI DataGrid - Adding a Pagination Component

jQuery EasyUI DataGrid - Adding a Pagination Component

This example demonstrates how to load data from the server and how to add a pagination component to the datagrid.

Create the DataGrid

To load data from a remote server, you should set the 'url' property, and your server should return data in JSON format. See the datagrid documentation for more information about its data format.



    

        

            

                

                

                

                

                

                

            

        

    
Item IDProduct IDList PriceUnit CostAttributeStauts

We define the datagrid columns and set the 'pagination' property to true, which generates a pagination toolbar at the bottom of the datagrid. Pagination will send two parameters to the server:

Server-side code



    $page = isset($_POST['page']) ? intval($_POST['page']) : 1;

    $rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;

    // ...

    $rs = mysql_query("select count(*) from item");

    $row = mysql_fetch_row($rs);

    $result["total"] = $row[0];

    

    $rs = mysql_query("select * from item limit $offset,$rows");

    

    $items = array();

    while($row = mysql_fetch_object($rs)){

        array_push($items, $row);

    }

    $result["rows"] = $items;

    

    echo json_encode($result);

Download the jQuery EasyUI example

jeasyui-datagrid-datagrid2.zip