MedicOneSystems / MedicOneSystems/livewire-datatables

View parameters..?

Open
#51 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
1.2k
Forks
257
PR merge metrics
No merged PRs in 30d

Description

Hi,

I'm playing around a bit with this package, great work so far!

I've noticed a few things missing that others might find useful as well, one of those things are "view parameters".

Your current view() method hardcodes which parameters are available in the view, namely value and row.

My suggestion is to either pass an additional parameter to the function like:

view('myview', $params)

or to set it via an additional function, this is how I did it for my needs, keep in mind this is a dirty "hack" so I haven't checked in much detail if there is a better way perhaps:

`class ExtendedColumn extends Column
{
public $viewParameters;

public function viewParameters($parameters)
{
    $this->viewParameters = $parameters;
    return $this;
}

public function view($view)
{
    $this->callback = function ($value, $row) use ($view) {
        $params = array_merge(['value' => $value, 'row' => $row, 'name' => $this->name], $this->viewParameters);
        return view($view, $params);
    };

    return $this;
}`

This enables me to have custom editing with a select instead of a default input field for example but it also enables other things as well...

ExtendedColumn::name('status') ->viewParameters(['options' => Invoice::STATUSES, 'table' => $this->table]) ->view('datatables::editable-select'),

Let me know what do you think of this idea and if you want I can submit a PR.

I'm toying around with some other stuff as well but I'll keep that in a separate issue.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the current view() method, which hardcodes value and row as the available parameters, and review how the rendered view receives them. Done means callers can provide additional parameters for custom views while retaining the existing parameters.

Written by the indexing model from the issue text.

Assessment

Tech stack
laravel, php
Domain
frontend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.