Extjs4.2+webAPI+EF实现分页以及webapi的数据传值
由于不明白分页的总数是怎么计算,不知道他的分页方式所以花费了好多功夫,现在弄出来了与大家分享下
1.首先是EF的简历,想必大家都清楚:添加-〉新建项-〉数据-〉Ado。net实体数据模型
2.就是后台数据也就是apiController,前台需要两个数据,一个是数据的总条数,第二个是要查询的分页数据
所以我们要建立一个实体,用于返回数据传送,由于多个页面都使用,多以用到了泛型。代码如下:
public class PageData<T>
{
//数据总数
public int TotolRecord { get; set; } //需要返回的数据
public T Data { get; set; } }
3.组织需要向前台返回的数据
/// <summary>
/// 获取所有的监控信息
/// </summary>
/// <returns></returns>
public PageData<Monitor[]> Get([FromUri]string _dc, [FromUri] int page, [FromUri] int start, [FromUri] int limit)
{
OlandHIPDBInterfaceTrackEntities db = new OlandHIPDBInterfaceTrackEntities(); //返回数据包含数据总数
PageData<Monitor[]> returnData = new PageData<Monitor[]>(); IQueryable<Monitor> data = from item in db.Monitor
orderby item.ID
select item; returnData.TotolRecord = data.ToArray().Length; data=data.Skip<Monitor>(start); data=data.Take<Monitor>(limit); returnData.Data =data .ToArray<Monitor>(); return returnData;
}
好了,后台数据准备完毕,那么就开始Extjs部分的了
4.Extjs部分我就直接上代码了
Ext.require([
'*',
'Ext.toolbar.Paging',
'Scripts.*'
]) Ext.onReady(function () { Ext.define('InterfaceTrackModel', {
extend: 'Ext.data.Model',
fields: [{
name: 'ID',
type: 'int',
useNull: true
},
'Invoker',
'MachineName',
'MachineIP',
'InvokeDate',
'Interface',
'InterfaceDes',
'IsSuccessed',
'ConsumeTime',
'ErrorMessage',
'Remark'
]
}); var InterfaceTrackStore = Ext.create('Ext.data.Store', {
autoLoad: true,
autoSync: true,
model: 'InterfaceTrackModel', //设置分页大小
pageSize: 20,
proxy: {
type: 'rest',
url: 'api/InterfaceTrack',
reader: {
type: 'json',
root: 'Data',
//获取数据总数
totalProperty: 'TotolRecord'
},
writer: {
type: 'json'
}
}
}); var selModel = Ext.create('Ext.selection.CheckboxModel', {
width: 55
}); //将时间转化为 2011-08-20 00:00:00 格式
//解决Ext4的formPanel通过grid的store查询问题 2012.2.22 jzr
function dateFormat(value) {
if (null != value) {
//return Ext.Date.format(new Date(value), 'Y-m-d H:i:s');
return Ext.Date.format(new Date(value), 'Y-m-d H:i:s');
}
else {
return null;
}
} Ext.define('Scripts.InterfaceTrackGrid', {
extend: 'Ext.grid.GridPanel',
title: '接口监控',
id: 'InterfaceTrackGrid',
initComponent: function () {
Ext.apply(this, {
closable: true, //是否可关闭
width: 400,
height: 300,
frame: true, store: InterfaceTrackStore,
iconCls: 'icon-user',
// selModel: selModel, viewConfig: {
getRowClass: function (record) {
return record.get('IsSuccessed') ? '' : 'error-row';
}
}, columns: [Ext.create('Ext.grid.RowNumberer', { width: 35, text: '序号' }),
{
text: '编号',
width: 50,
sortable: true,
dataIndex: 'ID'
}, {
text: '调用者',
width: 80, dataIndex: 'Invoker' }, {
header: '机器名',
width: 80,
sortable: true,
dataIndex: 'MachineName' }, {
text: '机器IP',
width: 100,
// xtype: 'checkcolumn',
dataIndex: 'MachineIP' }, {
text: '调用时间',
width: 140,
sortable: true,
dataIndex: 'InvokeDate',
renderer: dateFormat }, {
text: '调用接口',
width: 120,
sortable: true,
dataIndex: 'Interface' }, {
text: '接口描述',
width: 140,
sortable: true,
dataIndex: 'InterfaceDes' }, {
text: '是否成功',
width: 80,
sortable: true,
dataIndex: 'IsSuccessed' }, {
text: '耗时',
width: 80,
sortable: true,
dataIndex: 'ConsumeTime' }, {
text: '错误信息',
width: 160,
sortable: true,
dataIndex: 'ErrorMessage' }, {
text: '备注',
width: 80,
sortable: true,
dataIndex: 'Remark' }],
bbar: Ext.create('Ext.PagingToolbar', {
store: InterfaceTrackStore,
displayInfo: true,
displayMsg: '显示{0}-{1}条,共计{2}条',
emptyMsg: "没有数据"
})
}),
this.callParent(arguments);
}
});
//加载数据
// InterfaceTrackStore.load({
// params: {
// start: 0,
// limit: 20
// }
// });
})
这里注意的地方,前台接受数据的时候
reader: {
type: 'json',
root: 'Data',
//获取数据总数
totalProperty: 'TotolRecord'
},
检测后台传过来的数据,分页数据对应的是Data键值对,数据总数据条数为
TotolRecord键值对 最终效果图:

这里面还设计了webaip的传值接受问题,可以参考 webapi下如何传值
Extjs4.2+webAPI+EF实现分页以及webapi的数据传值的更多相关文章
- Extjs4.2+webAPI+EF实现分页以及webapi的数据传值(续)
现在领导又要增加功能,需要分页的时候,每页显示N条信息.由于是每个页面都要改,所有需要声明了一个扩展类代码如下: // Copyright : 欧蓝德畅电子技术有限公司. All rights res ...
- Asp.net WebApi + EF 单元测试架构 DbContext一站到底
其实关于webapi和Ef service的单元测试我以前已经写过相关文章,大家可以参考: Asp.net WebAPI 单元测试 单元测试 mock EF 中DbContext 和DbSet Inc ...
- .net core webapi+EF Core
.net core webapi+EF Core 一.描述: EF Core必须下载.net core2.0版本 Micorsoft.EntityFrameworkCore:EF框架的核心包Micor ...
- EF查询分页
static List<T> GetPageList(Func<T,bool> whereLambda,Func<T,object> orderLambda,int ...
- WebApi实现验证授权Token,WebApi生成文档等 - CSDN博客
原文:WebApi实现验证授权Token,WebApi生成文档等 - CSDN博客 using System; using System.Linq; using System.Web; using S ...
- 向上滚动或者向下滚动分页异步加载数据(Ajax + lazyload)[上拉加载组件]
/**** desc : 分页异步获取列表数据,页面向上滚动时候加载前面页码,向下滚动时加载后面页码 ajaxdata_url ajax异步的URL 如data.php page_val_name a ...
- EF如何操作内存中的数据以及加载相关联表的数据:延迟加载、贪婪加载、显示加载
之前的EF Code First系列讲了那么多如何配置实体和数据库表的关系,显然配置只是辅助,使用EF操作数据库才是每天开发中都需要用的,这个系列讲讲如何使用EF操作数据库.老版本的EF主要是通过Ob ...
- EF 连接MySQL 数据库 保存中文数据后乱码问题
EF 连接MySQL 数据库 保存中文数据后乱码问题 采用Code First 生成的数据库,MySQL数据库中,生成的表的编码格式为***** 发现这个问题后,全部手动改成UTF8(图是另一个表的 ...
- EF数据库初始化策略及种子数据的添加
EF数据库初始化策略及种子数据的添加 CreateDatabaseIfNotExists 判断当前数据库连接字符串对应的数据库是否存在,若不存在则根据代码定义的model进行创建 DropCreate ...
随机推荐
- 使用itext生成pdf的,各种布局
代码如下,jar包为itext.jar,itextAsia.jar,最好都是最新的 :2张图片也在最后贴出,把图片放到D盘可以直接生成制定格式的pdf. 最后生成的pdf如下: 代码如下: packa ...
- 2019swpuj2ee作业一:C/S,B/S的应用的区别
1.硬件环境不同: C/S 一般建立在专用的网络上, 小范围里的网络环境, 局域网之间再通过专门服务器提供连接和数据交换服务.B/S 建立在广域网之上的, 不必是专门的网络硬件环境,例与电话上网, ...
- React Native桥接器初探
本文假设你已经有一定的React Native基础,并且想要了解React Native的JS和原生代码之间是如何交互的. React Native的工作线程 shadow queue:布局在这个线程 ...
- python:a+=b 和a=a+b? 基础数据类型也不能乱用
python:a+=b 不等于a=a+b? a+=b 调用的是__iadd__方法,但是a+b调用的是__add__方法.对于自定义的对象,我们通过覆盖两个方法来实现+=和+操作,但是基础数据类型呢? ...
- Python学习第2章
1.字符串: python中创建字符串我们可以使用引号''或"'. python访问子字符串,可以使用方括号来截取字符串: var="hello world!" var2 ...
- 9.2 翻译系列:数据注解特性之---Column【EF 6 Code First系列】
原文链接:http://www.entityframeworktutorial.net/code-first/column-dataannotations-attribute-in-code-firs ...
- Increasing Subsequence (hard version)
首先讲一下题目大意:给你n个数,然后从最左边(L)或者最右边(R)取一个数生成出一个新的序列,对于这个序列的要求是递增的(注意是递增的,不能存在等于的情况)问这个序列有多长.并打印此操作. 这题就是忘 ...
- 【Spark调优】:如果实在要shuffle,使用map侧预聚合的算子
因业务上的需要,无可避免的一些运算一定要使用shuffle操作,无法用map类的算子来替代,那么尽量使用可以map侧预聚合的算子. map侧预聚合,是指在每个节点本地对相同的key进行一次聚合操作,类 ...
- javascript 最全面的数组操作合集
一.数组添加.删除.替换.截取操作 1.arr.unshift(1) 在数组头部添加一个元素 1 (直接改变原数组,返回值为添加元素后数组的length) 2.arr.shift() 在数组的头部删除 ...
- requestAnimFrame 动画的使用方法
//requestAnimFrame 封装,可以兼容所有浏览器 window.requestAnimFrame = (function(){ return window.requestAnimatio ...