Server Side Basic Data Binding

Server side data binding allow users to bind large data sets that are not directly accessible as a full collection in client side due to various reasons. Server side data binding can improve performance drastically for large data sets but integration is fairly complex compared to Client Side Basic and Client Side Stream Data Binding techniques. This data binding technique can be used to fetch data via HTTP GET requests on demand.

Unlike in Client Side Basic, Server Side rendering will request for data on dropdown initialization and whenever user performs Server Side Filtering operation. Ornamentum has provided an optional opinionated service to integrate external data sources. However, you can build a custom data provider depending on your requirement.

What You Will See

Select
import { Component } from '@angular/core';

import { DropdownDataBindCallback, DropdownHttpResourceFactoryService } from 'ornamentum';

import { ExampleData } from 'helper-models';

@Component({
  selector: 'app-server-side-basic-usage',
  templateUrl: './server-side-basic-usage.component.html'
})
export class ServerSideBasicUsageComponent {
  public onDataBind: DropdownDataBindCallback<ExampleData>;

  constructor(private resourceFactory: DropdownHttpResourceFactoryService) {
    const exampleDataResource = resourceFactory.getResourceProvider<ExampleData>();
    this.onDataBind = exampleDataResource.onDataBind('/api/data');
  }
}

Basic Usage

onDataBind: DropdownDataBindCallback<any>   Default Value: undefinedTarget Component: <ng-dropdown>

Server side data bind functionality can be integrated via onDataBind callback function input property. Data source associated logic is decoupled from Ornamentum core module to make it data source agnostic.

  1. Import DropdownResourceModule along with DropdownModule.

    import {HttpClientModule} from "@angular/common/http";
    
    import { DropdownModule, DropdownResourceModule } from 'ornamentum';
    
    @NgModule({
     ...
     imports: [
        ...
        HttpClientModule, // Import http client module which is required for server side basic data binding
        DropdownModule.forRoot(), // Import dropdown module
        DropdownResourceModule.forRoot() // Import dropdown resource module
      ]
    })
    
  2. Within the target component use DropdownHttpResourceFactoryService to construct an instance of DropdownHttpDataFetchService<T> class. Invoke onDataBind method with the API resource path to get the data bind callback function reference.

    @Component({
      ...
    })
    export class ServerSideBasicUsageComponent {
      public onDataBind: DropdownDataBindCallback<ExampleData>;
    
      constructor(private resourceFactory: DropdownHttpResourceFactoryService) {
        const exampleDataResource = resourceFactory.getResourceProvider<ExampleData>();
        this.onDataBind = exampleDataResource.onDataBind('/api/data');
      }
    }
    

    or else you can write your own custom data provider without using getResourceProvider in DropdownHttpResourceFactoryService service. The custom data provider needs to return a function which is supposed to be returned object as Observable. As long as your data return as observable you can use any data sources such as Firebase Realtime Database or Cloud Firestore. Please refer Custom Data Provider documentation for more information.

  3. Set the obtained data bind function reference and load data on scroll boolean to onDataBind and loadOnScroll input properties of dropdown accordingly.

    <ng-dropdown
      ...
      [loadOnScroll]="true"
      [onDataBind]="onDataBind">
    </ng-dropdown>
    

Data fetch HTTP request (Your backend REST API) should support following

  1. Data loading query parameters

    • limit - The limit parameter controls the maximum number of items that may be returned for a single request. If limit is not specified, it will default to 30.

    • offset - The offset parameter controls the starting point within the collection of resource results. For example, if you have a collection of 15 items to be retrieved from a resource and you specify limit=5, you can retrieve the entire set of results in 3 successive requests by varying the offset value: offset=0, offset=5, and offset=10. Note that the first item in the collection is retrieved by setting a zero offset.

    i.e: data GET request URL generated when scrolling down to see more items.

    https://ornamentum.app/api/data?limit=30&offset=30

  2. Filtering query parameters - query parameters with field name and filter value will get appended when filtering is applied. The format of these query parameters are as follows.

    <field name>=[<name of the field>]&<filter value>=[<filter keyword>]

    • field name - Dropdown filter field. Target field is appended as a query parameter only when filtering is applied on dropdown by enabling filterable.

    • filter value - Filter value is passed when filterable property is enabled. Filter value is passed as string.

    Usage scenarios and examples

    1. filtering applied - filter and sort order values are appended to the request URL via a query parameter with target field name.

      i.e: data GET request URL generated when Product Type filed is filtered by 'cook' keyword.

      https://ornamentum.app/api/data?limit=30&offset=0&field=productType&filter=cook

    2. filtering not applied - field name and filter value is not appended to the request URL as a query parameter.

      i.e: data GET request URL generated when Product Type field is not filtered.

      https://ornamentum.app/api/data?limit=30&offset=0

    Refer Item Filtering documentation for more information and how to filtering.

  3. Service should respond follow DropdownQueryResult<T> schema. However, you can pass a custom response mapper callback function to onDataBind and map the response to DropdownQueryResult<T> schema without making changes in backend API response.

You can inspect network traffic of this page with "/api/data" filter in browser developer tools to understand backend service requests and behaviors for above example.

  Request URL: https://ornamentum.app/api/data?limit=30&offset=0
  Request Method: GET

Custom Data Provider

Server side and client side data binding can be implemented via a custom data provider as Ornamentum data sources are fully decoupled from component logic. Please refer Custom Data Provider for more information.

Client Side Basic Data Binding
Server Side Web Socket Data Binding
API Doc for Server Side Basic Data Binding