起步软件技术论坛
搜索
 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 3815|回复: 0

[分享] 通过cData完成数据查询和分页

  [复制链接]

54

主题

257

帖子

827

积分

高级会员

Rank: 4

积分
827
发表于 2018-1-30 09:45:24 | 显示全部楼层 |阅读模式
1.自定义action,action中添加三个参数,limit(每页显示条数,Integer),offset(起始数,Integer),filterStr(过滤条件,String),然后生成procedure
微信截图_20180130090530.png

2.点击代码,编写查询数据和分页的sql
  1.         public static Table test(Integer limit, Integer offset, String filterStr) {
  2.                 // 设置where条件
  3.                 String whereStr = " where 1=1 ";
  4.                 if (!filterStr.isEmpty()) {

  5.                         whereStr += " and " + filterStr;
  6.                 }

  7.                 String sql = "SELECT o as fOrderID, o.* FROM DEMO_Orders o " + whereStr + " limit " + offset + ", " + limit;
  8.                 // 传入参数并执行SQL
  9.                 Table table = KSQL.select(sql, null, "/demo/common/data", null);//
  10. //                 table.getMetaData().setKeyColumn("fOrderID"); // 此方法也可以使用b
  11.                 table.getProperties().put("sys.rowid", "fOrderID");
  12.                 String cntSql = "SELECT count(o) as cn FROM DEMO_Orders o " + whereStr;

  13.                 Table cntTable = KSQL.select(cntSql, null, "/demo/common/data", null);
  14.                 int cnt = 0;
  15.                 if (cntTable.iterator().hasNext()) {
  16.                         cnt = cntTable.iterator().next().getInt(0);
  17.                 }
  18.                 table.getProperties().put("sys.count", cnt);
  19.                 System.out.println(cnt);
  20.                 return table;
  21.         }
复制代码
3.在.w页面,放一个cData,在数据组件的接管刷新事件中,写传参和调用action代码
  1.         Model.prototype.data1CustomRefresh = function(event) {
  2.                 var options = {};
  3.                 var param = new biz.Request.ActionParam();       
  4.                 param.setInteger('limit', event.limit);
  5.                 param.setInteger('offset', event.offset);
  6.                 param.setString('filterStr', " o.fOrderDate < SQL.str_to_date('1998-01-08','%Y-%m-%d')");
  7.                 var process = "/demo/misc/process/CDataDemo/cDataDemoProcess";
  8.                 var activity = "mainActivity";

  9.                 options.contentType = 'application/json';
  10.                 options.dataType = "json";
  11.                 options.process = process;
  12.                 options.activity = activity;
  13.                 options.parameters = param;
  14.                 options.action = "testAction";
  15.                 options.callback = function(data) {
  16.                         if (data.state) {
  17.                                 // 成功
  18.                                 event.source.loadData(data.response);
  19.                         } else {
  20.                                 // 失败
  21.                                 Request.errorMessage(resultData, "执行失败!", null, null);
  22.                         }
  23.                 };
  24.                 var result = biz.Request.sendBizRequest(options);
  25.         };
复制代码


评分

参与人数 1威望 +20 收起 理由
wgs7909 + 20 必须加分。

查看全部评分

目前不用这个平台啦~~
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|X3技术论坛|Justep Inc.    

GMT+8, 2024-5-2 11:15 , Processed in 0.069614 second(s), 29 queries .

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表