Custom DataSource

A custom data source is an instance class that extends from the DataSource abstract class.

We name Custom DataSource when you provide a data source that extends from the abstract class DataSource.

When the DikeGrid receives this type of data source, it connects to this DataSource and creates an instance of the type DikeGridDataSource, wrapping every data entry into a DikeGridDataRowEntry row.

Same as In-Memory DataSource, after wrapping operation, the DikeGrid assigns and emits a unique id. It also sets a unique id for every row.

See the following code snippet:

<dike-grid id="grid-custom-datasource" height="600px" #grid="dkgGrid"
    (dataDeliveryIdChange)="onDataDeliveryIdChange($event)">
</dike-grid>
  1. After querying the DikeGrid instance from the component's view, we create a CustomDataSource object passing in all the dependencies to implement the logic for this data source.

  2. We obtain the data from a REST API. This API is a mock service that runs in memory. That is why we delay every invocation 350 milliseconds.

  3. The REST API receives the filtering and sorting event data to process them behind the REST API.

  4. For the sake of brevity, we execute the pagination operation in the client after receiving the response from the REST API.

Be aware that the DikeGrid will wrap every response from the REST API assigning new ids for every row and a unique id for the whole data set. The DikeGrid also resets the edition and selection operations. It means that the DikeGrid removes the history of changes and deselects rows.

DataSource decorators

Once you assign your custom data source to the DikeGrid instance, it connects to that data source.

See the following diagram:

The DikeGridDataSource wraps every data entry into a row of the type DikeGridDataRowEntry.

If you have allowed the edition operation, the DikeGrid creates the following decorators:

The DikeGrid creates the edition decorators only if you allow edition because the DikeGrid manages all the edition operations in memory.

You can not assign custom decorators when you provide a Custom DataSource.

Row grouping operation is not allowed when you provide a Custom DataSource.

Summary

You can provide a custom data source to the DikeGrid. For example, a custom data source could take remote data entries.

The DikeGrid manages the edition operation by adding the corresponding decorators.

Be aware that you can not group rows or assign custom decorators.

Complete code for this section

<div class="flex-none w-56 flex flex-col m-2 items-center">
    <button mat-raised-button
        class="flex-none w-56 my-2"
        color="primary"
        (click)="onClearFilter()">Clear Filter
    </button>
</div>

<dike-grid id="grid-custom-datasource" height="600px" #grid="dkgGrid"
    [displayRowId]="gridProperties.displayRowId"
    [gridElevation]="gridProperties.matElevation"
    [gridElevationValue]="gridProperties.elevationValue"
    [striped]="gridProperties.stripeRows"
    [verticalRowLines]="gridProperties.verticalRowLines"
    
    (dataDeliveryIdChange)="onDataDeliveryIdChange($event)"
    
    [allowSelection]="gridProperties.allowSelection"
    [allowRowFiltering]="gridProperties.allowRowFilter"
    [allowSorting]="gridProperties.allowSorting"
    [allowPagination]="gridProperties.allowPagination"
    [pageSize]="gridProperties.pageSize"
    
    (filterChange)="onFilterChange($event)"
    (editionFilterChange)="onEditionFilterChange($event)"
    
    (selectionChange)="onSelectionChange($event)"
    (editionRowChange)="onEditionRowChange($event)"
    (updateRowChange)="onUpdateRowChange($event)"
    (cancelRowEditionChange)="onCancelRowEditionChange($event)"
    (removeRowChange)="onRemoveRowChange($event)"
    (restoreRowChange)="onRestoreRowChange($event)"
    
    allowEdition
    [editionMode]="gridProperties.editionMode"
    
    [datasource]="dkgDataSource">

    <dike-grid-column
        fieldName="employeeId"
        headerText="Employee Id"
        dataType="Text"
        width="350"
        sortable>
    </dike-grid-column>

    <dike-grid-column
        fieldName="country"
        headerText="Country"
        dataType="Text"
        width="250"
        sortable>
    </dike-grid-column>
    
    <dike-grid-column
        fieldName="completeNameGroup"
        headerText="Complete Name">

        <dike-grid-column
            fieldName="firstName"
            headerText="Name"
            dataType="Text"
            width="150"
            sortable
            editable>
        </dike-grid-column>

        <dike-grid-column
            fieldName="lastName"
            headerText="Surname"
            dataType="Text"
            width="150"
            sortable
            editable>
        </dike-grid-column>

    </dike-grid-column>
    
    <dike-grid-column
        fieldName="gender"
        headerText="Gender"
        dataType="Binary"
        width="130"
        sortable>
    </dike-grid-column>

    <dike-grid-column
        fieldName="age"
        headerText="Age"
        dataType="Numeric"
        contentAlign="center"
        width="100"
        sortable
        editable>
    </dike-grid-column>
    
    <dike-grid-column
        fieldName="email"
        headerText="Email"
        dataType="Text"
        width="300"
        sortable
        editable>
    </dike-grid-column>

    <dike-grid-column
        fieldName="hireDate"
        headerText="Hire Date"
        dataType="Date"
        sortable
        editable>
    </dike-grid-column>

</dike-grid>
    

Last updated