Streams Module - How do i override Table UI to set custom columns and sort.

mattcdavis1 - 3 months ago

I've tried adding the following in my module service provider but not sure how to return what is expected:

$this->bindings = [ 'anomaly.module.streams::ratiochristi.apologeti_ticker.table' => function() { return app('Datacode\DatacodeModule\Ui\Table\ApologetiTicker'); }, ];

The ApologetiTicker class extends Anomaly\Streams\Platform\Ui\Table\TableBuilder but when i use this binding i get an error: Method Datacode\DatacodeModule\Ui\Table\ApologetiTicker::handle() does not exist

ryanthompson - 3 months ago

Try just a normal binding:

$this->bindings = [
    'anomaly.module.streams::ratiochristi.apologeti_ticker.table' => \Datacode\DatacodeModule\Ui\Table\ApologetiTicker::class,
];

It's expecting a concrete and not an instance.

mattcdavis1 - 3 months ago

I started with that but it didn't work. that's why i went the more complicated route.

mattcdavis1 - 3 months ago

I did finally get it working using the following:

public function __construct(Application $app, Addon $addon)
    {
        parent::__construct($app, $addon);

        $this->bindings = [
            'anomaly.module.streams::ratiochristi.apologeti_ticker.table' => function() {
                $streams = app('Anomaly\Streams\Platform\Stream\Contract\StreamRepositoryInterface');
                $stream = $streams->find(28);
                $builder = $this->dispatch(new TableCommand($stream));

                return $builder;
            },
        ];
    }

mattcdavis1 - 3 months ago

The problem with the approach you mentioned is that the streams module is expecting a command not a table builder and the command needs a concrete stream instance. As far as i can tell only way to get this is the approach above or what you had posted (except swap out uibuilder for command) and then add another binding to pass in the concrete stream instance to the command.

mattcdavis1 - 3 months ago

But now i'm still trying to figure out how to show created_at as a column. when i add created_at via ->setColumns(['created_at', 'title']) this is what i see: https://goo.gl/52D4Ku

Also trying to figure out how to set sort order to reverse chronological.

mattcdavis1 - 3 months ago

Ok, figured out how to set order: $builder->->setTableOption('order_by', ['created_at' => 'desc']). Now just need to figure out:

  • Why is created_at not showing the actual value?
  • is there a simpler way to set order field/direction and headings? current approach is to:
    • create a custom module
    • create a custom command
    • bind "anomaly.module.streams::{$namespace}.{$stream}.table" to my custom command
    • modify builder settings

ryanthompson - 3 months ago

You should be able to use entry.created_at I believe. You have to include entry cause it's not a field.

ryanthompson - 3 months ago

Why is it looking for a command? Are you on 1.1?

https://github.com/anomalylabs/streams-module/blob/1.1/src/Entry/Command/GetEntryTableBuilder.php#L54

mattcdavis1 - 3 months ago

I am on 1.1 yes. You're right it's not looking for a command but the way that this the builder is created uses a command: $builder = $this->dispatch(new GetDefaultTableBuilder($this->stream)); (GetDefaultTableBuilder is a command)

So, although the result is not a command, a command is used to create $builder. When i simply return a UI Table it fails looking for a handle method. If there is an easier way that's fine, but so far the code i've posted above is the only way i can get it to work. is there an easier way (your first response didn't work)?

ryanthompson - 3 months ago

Ok update - I added an EntryTableBuilder to make it more better :-P

This works for me:

<?php namespace App\Table;

use Anomaly\StreamsModule\Entry\Table\EntryTableBuilder;

class TestTableBuilder extends EntryTableBuilder
{

    protected $columns = [
        'entry.id',
        'name'
    ];
}

Then binding it like this (in my case in <?php namespace App\Table; use Anomaly\StreamsModule\Entry\Table\EntryTableBuilder; class TestTableBuilder extends EntryTableBuilder { protected $columns = [ 'entry.id', 'name' ]; } ):

'bindings' => [
    'anomaly.module.streams::example.people.table' => \App\Table\TestTableBuilder::class,
],

mattcdavis1 - 3 months ago

yep - that works great. thanks! and the entry.id example is what i needed to figure out the created_at issue (needed to be entry.created_at