数据源分页问题(修订) [英] Datasource Paging Issue (Revised)

查看:70
本文介绍了数据源分页问题(修订)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个简单的测试设置:部门:员工,1:M和一个搜索表单,该表单可以过滤Emploee FirstName =,lastname =,电子邮件包含,年龄> =,加入日期< =和相关部门=.

A simple testing setup: department: employee, 1:M and a search form that allows filtering on Emploee FirstName =, lastname =, email contains, age >=, join date <= and related department =.

一种搜索表单,其中的窗口小部件绑定到云SQL数据源查询脚本的参数.

A search form with widgets bound to parameters of a cloud SQL datasource query script.

搜索表单上的提交"按钮打开一个查询结果页面,该页面的表绑定到云SQL查询脚本数据源.

A Submit button on the search form which opens up a query results page with a table bound to the cloud SQL query script datasource.

查询脚本

var params = query.parameters;

var params = query.parameters;

return getEmployeeRecords_( 
  params.param_FirstName, 
  params.param_LastName, 
  params.param_Email, 
  params.param_StartDate, 
  params.param_Age, 
  params.param_Department
);

function getEmployeeRecords_( firstName, lastName, email, startDate, age,     
department) {

 var ds = app.models.Employee.newQuery();

 if ( firstName !== null ) {
    ds.filters.FirstName._equals = firstName;
 }
 if ( lastName !== null ) {
    ds.filters.LastName._equals = lastName;
 }
 if ( email !== null) {
    ds.filters.Email._contains = email;
 }
 if ( startDate !== null) {
    ds.filters.StartDate._greaterThanOrEquals = startDate;
 }
 if ( age !== null) {
    ds.filters.Age._lessThanOrEquals = parseInt(age, 10);
 }
 if ( department !== null) {
    ds.filters.Department.Department._equals = department;
 }

 var records = ds.run();

 // intention is to store this value for future use
 var recs = records.length;

 return records;
}

在查询脚本的结果页面上,数据源分页刚刚中断.正确返回8条记录(其中查询页面大小设置为5)的查询使我可以让分页器转到第1000页,但是数据源始终停留在记录的第一页上.将页面大小设置为例如100,可以清楚地显示正确的结果集.

On the results page for the query script datasource paging is just broken. A query that correctly returns 8 records where the query page size is set to 5 allows me to get the pager to go to page 1000 if I wished, but the datasource always stays on the first page of records. With page size set to e.g., 100 the correct result set is clearly displayed.

实际上,我对这种查询所做的所有操作都有分页问题.如果我插入这段代码

In fact everything I do with this sort of query has paging issues. If I insert this code

var ds = app.models.Employee.newQuery();
//ds.filters.FirstName._equals = firstName;
//ds.filters.LastName._equals = lastName;
//ds.filters.Email._contains = '.com';
//ds.filters.StartDate._greaterThanOrEquals = startDate;
ds.filters.Age._lessThanOrEquals = 40;
//ds.filters.Department.Department._equals = department;
ds.sorting.Age._ascending();
var records = ds.run();
return records;

直接进入数据源查询脚本,我仍然遇到类似的分页问题.

directly into the datasource query script I still have similar paging issues.

如果我使用查询构建器脚本,例如

If I use a query builder script such as

(
FirstName =? :param_FirstName and
LastName =? :param_LastName and
Email contains? :param_Email and
StartDate >=? :param_Startdate and
Age <=? :param_Age and
Department.Department =? :param_Department
)

和诸如

@ datasources.Search_Query_Builder.query.parameters.param_FirstName

@datasources.Search_Query_Builder.query.parameters.param_FirstName

这没有问题.直接过滤也是如此,在这种情况下,我们使用诸如

this works without issue. The same with direct filtering, where we use bindings such as

@ datasources.Employee.query.filters.FirstName._equals

@datasources.Employee.query.filters.FirstName._equals

任何人都认为这玩意儿有什么毛病.我们需要查询脚本来实现更好的控制,例如检索记录计数的能力以及在限制数据的条件下必须进行过滤的能力,例如登录的用户与客户端有关,而客户端又与属性有关,并且属性值根据客户端受到限制.

Anyone any ideas in terms of what is wrong with this stuff. We need query scripts for more controle, e.g., the ability to retrieve a count of records and where you have to filter for a condition where you restrict data, e.g. a logged in user is related to a client which in turn is related to a property and the property value is restricted according to client.

...仅查看正在开发的真实应用程序,并在数据源查询脚本编辑器中使用查询脚本,没有参数,没有绑定,仅此代码:-

... Just looking at a real application under development and the use of a query script within the datasource query script editor, no parameters, no binding, just this code:-

var ds = app.models.Incident.newQuery();
ds.filters.Id._greaterThanOrEquals = 200;
ds.filters.Id._lessThanOrEquals = 300;
var records = ds.run();
return records;

,将页面大小设置为20,然后再次使页面分页,即使页面号增加,也永远不会移出记录的第一页.

and a page size set to 20 and again the paging is up the creek, never moves beyond the first page of records despite the page number incrementing.

推荐答案

尽管尚不清楚到底是什么导致了页面调度问题,以及我的建议是否可以解决基本问题,我还是对如何解决此问题提出了一些建议. .但是,在我自己的应用程序环境中,我有几个实例,在这些实例中,我使用标准SQL模型,然后将过滤器应用于该模型的数据源,然后具有并发计算模型(数据源),该模型返回满足所应用过滤器的记录总数到我的其他数据源.我们开始:

I have some suggestions how to address this issue, although it is still unclear what exactly is causing the paging issue and whether or not my suggestions will fix the underlying issue. However, in my own application environment I have several instances where I use a standard SQL model and I apply filters to a datasource from that model and then have a concurrent calculated model (datasource) that returns the total count of records that meet the filters applied to my other datasource. Here we go:

在您的Employee模型下创建一个新的数据源,将其保留为默认的"Query Builder"类型,根据您的偏好调整查询页面的大小,但最好将其调整为您知道的内容,当您查询该数据源时将返回一页以上的记录数据源.取消选中自动加载数据"属性,除非您想在首次进入设置过滤器的页面时加载所有记录.不要在查询构建器中输入任何内容.

Create a new datasource under your Employee model, leave it on the default 'Query Builder' type, adjust the query page size to your preference, but preferably to something that you know will return more than one page of records when querying the datasource. Uncheck the 'automatically load data' property unless you want to load all records when first going to your page where you set your filters. Do not enter anything in the query builder.

对于您称为Employee_RecordCount的计算出的数据源,请添加参数,FirstName_equals,LastName_equals,Email_contains,StartDate_greaterequals,Age_lessequals和Departments_equals(如果尚未添加).在此计算模型中,您应该有一个称为RecordCount的字段.在此数据源的查询脚本部分中,应将函数设为return getEmployeeRecords_(query).

For the calculated datasource that you called Employee_RecordCount add your parameters, FirstName_equals, LastName_equals, Email_contains, StartDate_greaterequals, Age_lessequals, and Departments_equals, if you have not already. In this calculated model you should have a field called RecordCount. In the query script section of this datasource you should put your function as return getEmployeeRecords_(query).

在服务器脚本部分中,getEmployeeRecords函数所在的代码如下:

In your server script section where your getEmployeeRecords function is the code should be as follows:

function getEmployeeRecords_(query) {
 var params = query.parameters;
 var ds = app.models.Employee.newQuery();

 if (params.FirstName_equals !== null ) {
    ds.filters.FirstName._equals = params.FirstName_equals;
 }
 if (params.LastName_equals !== null ) {
    ds.filters.LastName._equals = params.LastName_equals;
 }
 if (params.Email_contains !== null) {
    ds.filters.Email._contains = params.Email_contains;
 }
 if (params.StartDate_greaterequals !== null) {
    ds.filters.StartDate._greaterThanOrEquals = params.StartDate_greaterequals;
 }
 if (params.Age_lessequals !== null) {
    ds.filters.Age._lessThanOrEquals = parseInt(params.Age_lessequals, 10);
 }
 if (params.Department_equals !== null) {
    ds.filters.Department.Department._equals = params.Department_equals;
 }
 var records = ds.run();

 // update calculated model with record count
 var calculatedModelRecord = app.models.Employee_RecordCount.newRecord();
 calculatedModelRecord.RecordCount = records.length;

 return [calculatedModelRecord];
}

现在转到搜索页面,创建一个新面板或将其设置为与您创建的新数据源相同的表单.确保您拥有所有适当的字段,并将这些字段的绑定更改为:

Now go to your search page, create a new panel or form set it to the same new datasource that you created. Make sure you have all your appropriate fields and change the binding of these fields to:

@datasource.query.filters.firstName._equals
@datasource.query.filters.lastName._equals
@datasource.query.filters.email._contains
@datasource.query.filters.StartDate._greaterThanOrEquals
@datasource.query.filters.Age._lessThanOrEquals
@datasource.query.fitlers.Department.Department._equals

启动搜索的按钮应具有以下代码:

The button that initiates your search should have the following code:

var ds = widget.datasource;
ds.load(function() {
  app.showPage(app.pages.YourSearchResultPage);
}
var calculatedDs = app.datasources.Employee_RecordCount;
var props = calculatedDs.properties;
props.FirstName_equals = ds.query.filters.firstName._equals;
props.LastName_equals = ds.query.filters.lastName._equals;
props.Email_contains = ds.query.filters.email._contains;
props.StartDate_greaterequals = ds.query.filters.StartDate._greaterThanOrEquals;
props.Age_lessequals = ds.query.filters.Age._lessThanOrEquals;
props.Department_equals = ds.query.filters.Department.Department._equals;
calculatedDs.load();

现在转到搜索结果页面,并确保您具有以下元素:

Now go to your search result page and make sure the you have the following elements:

  1. 将数据源设置为Employee_RecordCount的面板.里面 此面板创建标签并将绑定设置为 @datasource.item.RecordCount.
  2. 具有数据源集的表 到第一步中创建的相同数据源.确保你的 表格已启用分页"功能.
  1. A panel that the datasource is set to Employee_RecordCount. Inside this panel create a label and set the binding to @datasource.item.RecordCount.
  2. A table that has the datasource set to the same datasource as created in the first step. Make sure your table has 'pagination' turned on.

仅此而已,这在我的应用程序中有效.设置起来很麻烦,但恐怕这是拥有记录总数的唯一解决方法.我应该指出,我也从未遇到过任何分页问题.

That should be all, and this works in my application. It is a pain to set up, but I'm afraid it is the only workaround to have a total count of records. I should note that I have never had any paging issues either.

这篇关于数据源分页问题(修订)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆