Extjs 分页实例 后台php

前台js

Ext.onReady(function(){

	var store = Ext.create(‘Ext.data.JsonStore‘,{
		proxy: {
			type: ‘ajax‘,
			url: ‘role.php‘,
			reader:{
				type: ‘json‘,
				root:‘systemLogs‘,
				totalProperty: ‘totalCount‘ //注意这里的拼写错误
			}
		},
		pageSize: 5,
		autoLoad: true,
		fields: [
	        {name: ‘time‘,  type: ‘date‘},
	        {name: ‘username‘},
	        {name: ‘type‘, type: ‘string‘},
	        {name: ‘ipAddress‘},
	        {name: ‘content‘, type: ‘string‘}
	    ] 
	});
	
	
	var my_grid = Ext.create(‘Ext.grid.Panel‘,{
		xtype: ‘grid‘,
		store: store,
		renderTo:Ext.getBody(),
		columns: [ 
			new Ext.grid.RowNumberer(),
			{ text: ‘操作时间‘, sortable : true, dataIndex: ‘time‘, width:200},
			{ text: ‘操作账号‘, sortable : true, dataIndex: ‘username‘}, 
			{ text: ‘操作类型‘,  sortable : true,dataIndex: ‘type‘},
			{ text: ‘IP地址‘, sortable : true, dataIndex: ‘ipAddress‘, width:200}, 
			{ text: ‘操作内容‘, sortable : true, dataIndex: ‘content‘, width:400}
		],	
		bbar: {
			xtype: ‘pagingtoolbar‘,
			pageSize: 5,
			store: store,
			displayInfo: true
		}
	});	
});

role.php

<?php
	$content = json_decode(file_get_contents(‘data.json‘), true); //获取json内容,并且保存为数组格式
	
	$start = isset($_REQUEST[‘start‘])?$_REQUEST[‘start‘]:0;
	$limit = isset($_REQUEST[‘limit‘])?$_REQUEST[‘limit‘]:5;
	
	$count = count($content[‘systemLogs‘]);
	for($i = $start; $i < $limit+$start; $i++) {
		$data_out[] = $content[‘systemLogs‘][$i];
	}
		
	echo json_encode(array(‘success‘=>true,‘totalCount‘=>$count,‘systemLogs‘=>$data_out));
?>

 data.json

{
    "systemLogs": [
        {
            "content": "删除用户",
            "endTime": "2014-12-11 17:01:04",
            "id": "3",
            "ipAddress": "192.168.0.1",
            "startTime": "2014-12-11 17:01:04",
            "time": "2014-12-11 17:01:04",
            "type": 2,
            "username": "李四"
        },
        {
            "content": "删除用户",
            "endTime": "2014-12-11 17:01:08",
            "id": "4",
            "ipAddress": "192.168.0.1",
            "startTime": "2014-12-11 17:01:08",
            "time": "2014-12-11 17:01:08",
            "type": 2,
            "username": "李四"
        },
        {
            "content": "用户[admin]于[2015-01-09]在[192.168.1.161]修改了登入密码",
            "endTime": "",
            "id": "402881214ace09a2014ace14acc50000",
            "ipAddress": "192.168.1.161",
            "startTime": "",
            "time": "2015-01-09 17:44:29",
            "type": 3,
            "username": "admin"
        },
        {
            "content": "用户[admin]于[2015-01-09]在[192.168.1.161]修改了登入密码",
            "endTime": "",
            "id": "402881214ace09a2014ace14d1730001",
            "ipAddress": "192.168.1.161",
            "startTime": "",
            "time": "2015-01-09 17:44:38",
            "type": 3,
            "username": "admin"
        },
        {
            "content": "用户[admin]于[2015-01-13]在[192.168.1.161]修改了登入密码",
            "endTime": "",
            "id": "402881214ae12197014ae1226cb00000",
            "ipAddress": "192.168.1.161",
            "startTime": "",
            "time": "2015-01-13 10:32:17",
            "type": 3,
            "username": "admin"
        },
        {
            "content": "用户[admin]于[2015-01-14]在[192.168.1.161]修改了登入密码",
            "endTime": "",
            "id": "402881214ae7dd2d014ae7e1e1ef0000",
            "ipAddress": "192.168.1.161",
            "startTime": "",
            "time": "2015-01-14 17:59:08",
            "type": 3,
            "username": "admin"
        },
        {
            "content": "用户[admin]于[2015-01-14]在[192.168.1.161]修改了登入密码",
            "endTime": "",
            "id": "402881214ae7dd2d014ae7eb8e9e0001",
            "ipAddress": "192.168.1.161",
            "startTime": "",
            "time": "2015-01-14 18:09:42",
            "type": 3,
            "username": "admin"
        },
        {
            "content": "用户[admin]于[2015-01-14]在[192.168.1.161]修改了登入密码",
            "endTime": "",
            "id": "402881214ae7dd2d014ae7ef64fb0002",
            "ipAddress": "192.168.1.161",
            "startTime": "",
            "time": "2015-01-14 18:13:53",
            "type": 3,
            "username": "admin"
        },
        {
            "content": "用户[admin]于[2015-01-14]在[192.168.1.161]修改了登入密码",
            "endTime": "",
            "id": "402881214ae7dd2d014ae7f004190003",
            "ipAddress": "192.168.1.161",
            "startTime": "",
            "time": "2015-01-14 18:14:34",
            "type": 3,
            "username": "admin"
        },
        {
            "content": "用户[admin]于[2015-01-14]在[192.168.1.161]修改了登入密码",
            "endTime": "",
            "id": "402881214ae7dd2d014ae7f310ad0004",
            "ipAddress": "192.168.1.161",
            "startTime": "",
            "time": "2015-01-14 18:17:54",
            "type": 3,
            "username": "admin"
        },
        {
            "content": "用户[admin]于[2015-01-14]在[192.168.1.161]修改了登入密码",
            "endTime": "",
            "id": "402881214ae7dd2d014ae7f41be40005",
            "ipAddress": "192.168.1.161",
            "startTime": "",
            "time": "2015-01-14 18:19:02",
            "type": 3,
            "username": "admin"
        },
        {
            "content": "用户[admin]于[2015-01-14]在[192.168.1.161]修改了登入密码",
            "endTime": "",
            "id": "402881214ae7f808014ae7fd09a80000",
            "ipAddress": "192.168.1.161",
            "startTime": "",
            "time": "2015-01-14 18:28:47",
            "type": 3,
            "username": "admin"
        },
        {
            "content": "用户[admin]于[2015-01-14]在[192.168.1.161]修改了登入密码",
            "endTime": "",
            "id": "402881214ae7f808014ae7ff938f0001",
            "ipAddress": "192.168.1.161",
            "startTime": "",
            "time": "2015-01-14 18:31:34",
            "type": 3,
            "username": "admin"
        },
        {
            "content": "用户[admin]于[2015-01-14]在[192.168.1.161]修改了登入密码",
            "endTime": "",
            "id": "402881214ae7f808014ae80445090002",
            "ipAddress": "192.168.1.161",
            "startTime": "",
            "time": "2015-01-14 18:36:41",
            "type": 3,
            "username": "admin"
        },
        {
            "content": "用户[admin]于[2015-01-14]在[192.168.1.161]修改了登入密码",
            "endTime": "",
            "id": "402881214ae7f808014ae804704f0003",
            "ipAddress": "192.168.1.161",
            "startTime": "",
            "time": "2015-01-14 18:36:52",
            "type": 3,
            "username": "admin"
        },
        {
            "content": "用户[admin]于[2015-01-14]在[192.168.1.161]修改了登入密码",
            "endTime": "",
            "id": "402881214ae7f808014ae805fbe10004",
            "ipAddress": "192.168.1.161",
            "startTime": "",
            "time": "2015-01-14 18:38:33",
            "type": 3,
            "username": "admin"
        },
        {
            "content": "用户[admin]于[2015-01-14]在[192.168.1.161]修改了登入密码",
            "endTime": "",
            "id": "402881214ae7f808014ae80627e20005",
            "ipAddress": "192.168.1.161",
            "startTime": "",
            "time": "2015-01-14 18:38:45",
            "type": 3,
            "username": "admin"
        },
        {
            "content": "用户[admin]于[2015-01-14]在[192.168.1.161]修改了登入密码",
            "endTime": "",
            "id": "402881214ae7f808014ae8075ce80006",
            "ipAddress": "192.168.1.161",
            "startTime": "",
            "time": "2015-01-14 18:40:04",
            "type": 3,
            "username": "admin"
        },
        {
            "content": "用户[admin]于[2015-01-14]在[192.168.1.161]修改了登入密码",
            "endTime": "",
            "id": "402881214ae7f808014ae8081f4d0007",
            "ipAddress": "192.168.1.161",
            "startTime": "",
            "time": "2015-01-14 18:40:54",
            "type": 3,
            "username": "admin"
        },
        {
            "content": "用户[admin]于[2015-01-14]在[192.168.1.161]修改了登入密码",
            "endTime": "",
            "id": "402881214ae80915014ae80a41d00000",
            "ipAddress": "192.168.1.161",
            "startTime": "",
            "time": "2015-01-14 18:43:13",
            "type": 3,
            "username": "admin"
        }
    ],
    "totalCount": 20
}

  

 

  

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。