Skip to content

Add a section for overriding the value of a Cell Component using the render function #3105

Description

@nmalinoski

Problem/task description:

The (https://orchid.software/en/docs/table/)[Table] and (https://orchid.software/en/docs/cell-types/)[Cell Types] documentation are lacking instructions to modify values before they are sent to Components.

Expected outcome:

Users will be able to learn how, on a Column by Column basis, to manipulate values before they're sent to Components without needing to create custom attributes on models or create/maintain custom Components that duplicate functionality of existing ones.

Proposed solution:

  1. First, either tweak the title of (https://orchid.software/en/docs/table/#customizing-component-values)[Customizing Component Values] to "Customizing Component Arguments" or integrate the information into Using Components; the point of this section appears to be demonstrating how the constructor arguments can be changed to work with individual values rather than a Model object. The word "Values" here is confusing, because it is the arguments being customized, not the incoming data.
  2. Second, add a new section to the Table documentation, after the arguments customization info, titled something like "Overriding Values Before Rendering with Components", with the following:

    If you need to override a value before it gets rendered by a Component, you can do so with the render function:

    TD::make('last_activity', __('Last Updated'))
        ->render(function (Order $order) {
            return (new DateTimeSplit(value: $order->shipped_at ?? $order->packed_at ?? $order->created_at))->render();
        })
    
  3. Lastly, add a new section (or integrate it into DateTimeSplit) with the following:

    If the updated_at column for your model defaults to null because it was created with nullable and useCurrentOnUpdate, DateTimeSplit will show the current date instead of a blank value or falling back to created_at, due to Carbon's behavior when provided with a null date. To have updated_at fall back to created_at, you can use the render function:

    TD::make('updated_at', __('Last Updated Test'))
        ->render(function (Order $order) {
            return (new DateTimeSplit(value: $order->updated_at ?? $order->created_at))->render();
        })
    

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

DocsMust be added to documentation

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions