Skip to content

Custom Backend Service

Ghislain B edited this page Jul 15, 2020 · 8 revisions

Topic and question discussed in this issue #524

Intro

The lib currently supports OData and GraphQL, if you want to use and create a different Backend Service, then follow the steps below.

Instructions

Yes you can add a different Custom Backend Service and Pagination as it is shown in this Example that was created by another user (for an Oracle DB if I remember correctly). The code for that example all have the swt prefix and I think this swt-common-grid.component.ts is the Backend Service one.

To create your own Custom Backend Service, I suggest you take the code of the GraphqlService and rewrite the internal of each methods. The thing to remember is that you have to implement the BackendService as defined in the GraphqlService (export class GraphqlService implements BackendService).

You typically want to implement your service following these TypeScript interfaces

At the end of it, you'll have a Custom Backend Service that will be instantiated just like the GraphQL or OData that I've created, it should look similar to this

this.gridOptions = {
      backendServiceApi: {
        service: new YourCustomBackendService(),
        options: {
          // custom service options that extends "backendServiceOption" interface
        },
        preProcess: () => !this.isDataLoaded ? this.displaySpinner(true) : '',
        process: (query) => this.getCountries(query),
        postProcess: (result) => {
          this.displaySpinner(false);
          this.isDataLoaded = true;
        }
      } as YourCustomBackendServiceApi
};

If you need to reference your Service for other purposes then you better instantiated in a separate variable and then just pass it to the service property of the backendServiceApi.

class MyComponent {
myCustomService = new YourCustomBackendService();

gridInit {
  this.gridOptions = {
      backendServiceApi: {
        service: this.myCustomService,
        // ...
      } as YourCustomBackendServiceApi
  };
}

If your Service is for a well known DB or API framework, then it might be possible to add your Service to the lib itself, however it should be added to the new monorepo lib Slickgrid-Universal in the list of slickgrid-universal/packages. Since that is a monorepo lib, users will have the ability to use and download only the package they need (which is not currently the case with Angular-Slickgrid 2.x version). More info here (read the section "What's coming in the Future (much later in the year)"), the Slickgrid-Universal lib is nearly all done but the next step, which will be long, is to rewrite Angular-Slickgrid to use it... anyway long story short, if you follow everything I wrote, it should also work with next major version and you could possibly contribute to the project as well if you wish to.

Contents

Clone this wiki locally