# Grid - Custom Inline Component

## Introduction

All GridMate components can be used as [inline components](/advanced-guides/inline-grid-setup.md)  just by configuration. However there is some situations where a custom component is required to address the business needs.

To address this type of use cases, you can implement your own Aura or LWC component. Both components should have recordId as an attribute.&#x20;

{% hint style="info" %}
If the component is an Aura component, it should be declared as a global as well as  the recordId attribute.
{% endhint %}

## Aura Implementation

### Aura Component

Our use case is to display a relative date based on the close date like a timer. Let's go ahead and start our custom Aura component using Lightning Data Service and relativeDateTime lightning component.

{% tabs %}
{% tab title="CloseDateTimerComponent.cmp" %}

```html
<aura:component implements="force:hasRecordId" access="global">
    <aura:attribute name="style" type="String" access="global" />

    <aura:attribute name="recordData" type="Object" />
    <aura:attribute name="recordError" type="String" />
    <aura:attribute name="closeDate" type="Object" />

    <aura:handler name="change" value="{!v.recordData}" action="{!c.handleRecordDateChange}" />

    <force:recordData
        aura:id="recordData"
        recordId="{!v.recordId}"
        fields="Name,CloseDate"
        targetFields="{!v.recordData}"
        targetError="{!v.recordError}"
    />

    <aura:if isTrue="{! v.closeDate }">
        <div class="slds-align_absolute-center">
            Closing&nbsp;
            <span style="{!v.style}">
                <lightning:relativeDateTime value="{!v.closeDate}" />
            </span>
        </div>
    </aura:if>
</aura:component>
```

{% endtab %}

{% tab title="CloseDateTimerComponentController.js" %}

```javascript
({
    handleRecordDateChange: function (component, event, helper) {
        component.set('v.closeDate', null);

        let recordData = component.get('v.recordData');
        if (recordData && recordData.CloseDate) {
            component.set('v.closeDate', new Date(recordData.CloseDate));
        }
    }
});
```

{% endtab %}
{% endtabs %}

### Inline Component Configuration

Our Aura component is ready. Let's go ahead and configure it as an inline component as below. Note that we can have dynamic attributes to customize the behavior per grid if needed. In our example, we are passing the style of the timer.

```json
[
    {
        "component": "c:CloseDateTimerComponent",
        "attributes": {
            "style": "font-size:large;color:blue"
        }
    }
]
```

<figure><img src="/files/sFNaOmN5WEOOGkJmvtWX" alt=""><figcaption><p>Close Date Timer - Aura</p></figcaption></figure>

## LWC Implementation

### LWC Component

LWC is also an option to implement an inline component. Below is the LWC version of the Close Date Timer component implemented above.

{% hint style="info" %}
The LWC component should be exposed. Otherwise it will not be visible to GridMate.
{% endhint %}

{% tabs %}
{% tab title="closeDateTimerLWC.html" %}

```html
<template>
    <template if:true={closeDate}>
        <div class="slds-align_absolute-center">
            Closing&nbsp;
            <span style={timerStyle}>
                <lightning-relative-date-time value={closeDate}>
                </lightning-relative-date-time>
            </span>
        </div>
    </template>
</template>
```

{% endtab %}

{% tab title="closeDateTimerLWC.js" %}

```javascript
import { LightningElement, api, wire } from 'lwc';

import { getRecord, getFieldValue } from 'lightning/uiRecordApi';

import CLOSE_DATE_FIELD from '@salesforce/schema/Opportunity.CloseDate';

export default class CloseDateTimerLWC extends LightningElement {
    @api recordId;
    @api timerStyle;

    @wire(getRecord, { recordId: '$recordId', fields: [CLOSE_DATE_FIELD] })
    recordData;

    get closeDate() {
        let oppCloseDate = getFieldValue(
            this.recordData.data,
            CLOSE_DATE_FIELD
        );

        if (oppCloseDate) {
            return new Date(oppCloseDate);
        }

        return null;
    }
}
```

{% endtab %}

{% tab title="closeDateTimerLWC.js-meta.xml" %}

```xml
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>58.0</apiVersion>
    <isExposed>true</isExposed>
</LightningComponentBundle>
```

{% endtab %}
{% endtabs %}

### Inline Component Configuration

Let's go ahead and configure the inline component as below:

```json
[
    {
        "component": "c:closeDateTimerLWC",
        "attributes": {
            "timerStyle": "font-size:large;color:blue"
        }
    }
]
```

And obviously we get the same result as a above.

<figure><img src="/files/2vKzexaUM7P7K6t6aCDy" alt=""><figcaption><p>Close Date Timer - LWC</p></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.gridmate.io/advanced-guides/grid-custom-inline-component.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
