Description

The Progress Data Source is an object that connects an Angular application with a Progress Data Object Service. It allows you to perform CRUD operations on a Data Object Service in TypeScript. It is available as an npm package on http://www.npmjs.com.

The declaration file declares two classes:

  • DataSource — This provides the integration layer to access the remote data resource. (Internally, it supports access to the JSDO.)
  • DataSourceOptions — This provides options to a Data Source instance.

DataSourceOptions Properties

Property Type Description
countFnName? string
  • The name of the remote invoke operation in the BusinessEntity that returns the total number of records in the data set.
  • Used when server paging is performed.
filter? any
  • Use it to specify client-side filtering of data.
  • Similar to the filter property of the kendo.data.DataSource class.
Example:

filter: {
    field: "State",
    operator: "eq",
    value: "MA"
}

jsdo progress.data.JSDO
  • This property is required.
  • It specifies the JSDO instance, which provides access to the resources of a Progress Data Object Service.
  • All other properties of the DataSourceOptions class are optional.
mergeMode? number An integer that represents a merge mode to use.Possible values are:
  • progress.data.JSDO.MODE_APPEND
  • progress.data.JSDO.MODE_MERGE
  • progress.data.JSDO.MODE_REPLACE
The default value is MODE_MERGE.
readLocal? boolean
  • If true, the read method does not perform a read operation on the remote service (if there is existing local data), but just returns the local data.
  • If false (the default), the read method allows access to data on the remote service.
  • It is useful to set readLocal to true for a child Data Source, when you develop a hierarchical app, for example.
skip? number Use it to specify how many records in the result set must be skipped before a page of data is returned.
sort? any
  • Use this object to specify sorting of data.
  • Similar to the sort property of the kendo.data.DataSource class.
Example:

sort: {
    field: "State",
    dir: "desc"
},

tableRef? string It refers to the temp table that is to be accessed as a resource.
Note: This property is required only if the specified jsdo represents a multi-table DataSet.
top? number Use it to specify the number of records to be returned from the result set.

DataSource Functions

Table 1. DataSource Functions
Function/API Description Input Output
read(params?: progress.data.FilterOptions): Observable<DataResult> It asynchronously retrieves data from the remote data resource. (Internally, it calls the jsdo.fill() method.)
  • progress.data.FilterOptions:
    
    interface FilterOptions { 
    filter?: any;
    id?: any;
    skip?: number;
    sort?: any;
    top?: number;
    }
  • The data retrieved is based on the specified filter property.
  • If none of the optional parameters is specified, then all the data is retrieved.
  • Returns an Observable.
  • If it succeeds, the observer's next() function returns an array of record objects along with the total number of record objects returned.
  • For a failure, the observer's error() function returns an Error object containing an error message.
getData(): <Array<object>> It returns an array of record objects that currently resides in local memory NA Returns an array of record objects.
create(data: object): object It creates a new record in local memory. data: An object that contains the details of the new record.
  • Returns the new record on success.
  • On failure, an exception is thrown.
findById(id: string): object It returns a copy of the record with the specified ID. id
Note: The existing implementation of the function uses JSDO's internal _id as the id property.
  • Returns the record with the specified ID.
  • On failure, it returns null.
update(data: any): boolean It updates a record in local memory. data: An object that contains the updated details for the record.
  • Returns true on success.
  • Else returns false.
remove(data: any): boolean It deletes a record from local memory. data: An object with a valid id of the record to be deleted.
  • Returns true if successful.
  • Else returns false.
hasCUDSupport(): boolean It indicates whether CUD (Create, Update and Delete) support is available in the underlying JSDO. NA
  • Returns true if CUD support is available.
  • Else returns false.
hasSubmitSupport(): boolean It indicates whether the underlying JSDO has Submit support (that is, provides a Submit operation). NA
  • Returns true if the corresponding JSDO has Submit support.
  • Otherwise, returns false.
saveChanges(): Observable<Array<object>> It synchronizes the Data Object service with all the record changes (CUD) pending in local memory. It is an asynchronous call. NA
  • Returns an Observable.
  • If it succeeds, the observer's next() function returns an object containing all changed rows.
  • For a failure, the observer's error() function returns an Error object containing an error message.

Example

The following example demonstrates how to instantiate a DataSource in TypeScript:

import { DataSource, DataSourceOptions } from "@progress/jsdo-nativescript";
import { progress } from "@progress/jsdo-core";

let jsdo:progress.data.JSDO, 
    session:progress.data.JSDOSession,
    dataSource: DataSource;

progress.data.getSession({
    serviceURI: uri,
    catalogURI: catUri,
    authenticationModel: "anonymous"
}).then((object) => {
    session = object.jsdosession;
    jsdo = new progress.data.JSDO({
        name: "Customer"
    });

    dataSource = new DataSource({
        jsdo: jsdo,
        tableRef: "ttCustomer"
    });
});
The following example demonstrates how to read data:
// This is a read with a filter, the filter is not required
dataSource.read({
    filter: {
        field: 'State',
        operator: 'eq',
        value: 'HI'
    }
}).subscribe((myData: DataResult) => {
    // You can also loop through myData.data instead of calling dataSource.getData()
    dataSource.getData().forEach(element => {
        // print out each customers CustNum
        console.log(element.CustNum);
    })
});
The following example demonstrates how to create a new record:
dataSource.create({
    CustNum: 100000,
    Name: 'testName',
    State: 'MA',
    Balance: 0
});
// You have to call saveChanges for the changes to propagate to the backend
dataSource.saveChanges().subscribe((myData) => {
    // process my data here
    myData.data.forEach((elem) => console.log(elem));
}, (error: Error ) => {
    // process error here
});

The following example demonstrates how to update a record:

dataSource.getData().forEach(element => {
    if (element.CustNum === 3000) {
        element.Name = "TestUser Foo"
        dataSource.update(element);
    }
});
// You have to call saveChanges for the changes to propagate to the backend
dataSource.saveChanges().subscribe((myData) => {
    // process data here
    myData.data.forEach((elem) => console.log(elem));
}, (error: Error ) => {
    // process error here
});

The following example demonstrates how to remove a record:

dataSource.getData().forEach(element => {
    if (element.CustNum === 9000) {
        dataSource.remove(element);
    }
});
// You have to call saveChanges for the changes to propagate to the backend
dataSource.saveChanges().subscribe((myData) => {
    // process data here
}, (error: Error ) => {
    // process error here
});
Note: saveChanges() only needs to be called when you are finished with your local changes. You do not need to call it for each individual operation.