.getDataSet()

Previous Next

Fetches records of a data source. These records can then be set in a data set of this data source, or used independently, for example as a list of possible values in an autocompletion input box.

Returns a Promise object or the 'this' object.

Syntax

.getDataSet( options )

 

options  ::=  {

      colRef:  columns

,     doCount: do-count

,     beginRec: begin-record-index

,     count: count

,     withQueryCondition: with-query-condition

,     condition: condition-object

,     getRows: get-rows

,     replace: replace

,     process: process-function

,     promise:  promise

,     success: success-function

,     error: error-function

}

 

do-count               ::= { true | false }

with-query-condition   ::= { true | false }

get-rows               ::= { true | false }

replace                ::= { true | false }

promise                ::= { true | false }

Options is a struct that can have the following items, all of which are optional.

columns is a comma-separated list of references to one or more columns of the data source. To refer to a column you can use its name or alias.

Do-count determines whether a count query must be performed in addition to the query action.

Begin-record-index is the record index number of the first record to be fetched. Its default is 1, which identifies the first record.

Count is the maximum amount of records to be queried. Normally, this is limited by the ‘Maximum Number of Records’ property of the data source, but this property allows to override. Specifying the ‘0’ value will fetch all matching records.

With-query-condition determines whether the current search values must be included in the query action. The default is ‘true’, but if a query is performed for an autocompletion field for a search condition, with-query-condition should be set to ‘false’.

Condition-object is a search condition object that identifies the subset of rows that you want to be fetched.

Get-rows specifies whether you want the rows delivered as the return value of the .getDataSet() function (either as a direct value, or as the value in a Promise settle function), or whether you want the rows placed in the data source’s row set instead.

Replace determines whether rows in a row set need to be completely replaced by the new row set. This setting is ignored when the get-rows is 'true'.

Process-function is an optional function used to transform the records returned by the server. If this function is specified, its results are passed as a return value or, if promises are used, as the .then() function.

Promise determines the return value of this function. If promise has the value of 'true' (the default), a Promise object is returned. If promise has the value of 'false', the ‘this’ object is returned instead. If get-rows has the value of 'true', then the result of the query is passed to the .then() function.

Success-function is a function called after the data was processed on the client.

Error-function is a function called if an error occurs.

 

Example 1

var cond = {};

cond[col.alias()] = ""; //all values of the column

dsc.getDataSet({

    colRef: col.alias(),

    getRows: true,

    condition: cond, 

    replace: false

}).then(function(result) {

    ...

});

 

Example 2

var condition = {};

condition[col] = v + "%";

 

$.udb(d).getDataSet({

    count: $.udb(d).dataSetSize(),

    getRows: true,

    replace: false,

    condition: condition,

    process: function(rows) {

        var values = [];

    ...

        for (var i = 0; i < rows.length; i++) {

            if (rows[i] && !check[rows[i][pkName]]) {

                if (!max || values.length < max)

                    values.push({

                        text: rows[i][colName], 

                        value: rows[i][pkName], 

                        rowData: rows[i], 

                        dsId: d, 

                        colName: colName, 

                        pkName: pkName});

                check[rows[i][pkName]] = true;

            }

        }

        return values;

    }

}).then(function(result) {

    //publish result

    ...

});