How To: Dynamic Table View Labels?
Created 5 years ago by finnito

Hey all!

I've got a little bit of a feature request or I want to know if it's possible! When implementing a UI table with views you can get a nice set of view labels. What I would like to do is to add, say, a number in brackets which represents the number of items in that table where I to click on it and look. This would make a nice addition to the feature because it would let you see into that table at a glace without having to check. A use-case of this could be if there are comments that need to be approved, or anything really!

I have just spent some time seeing if I can insert something dynamically into the view definition but it seems a bit static and I couldn't get it to play nice!

protected $views = [
    "enabled" => [
        "query" => EnabledQuery::class,
        "text" => "finnito.module.nzen::view.enabled",
    ],
    "disabled" => [
        "query" => DisabledQuery::class,
        'text'    => 'finnito.module.nzen::view.disabled',
    ],
    "all",
];

Thoughts?

ryanthompson  —  5 years ago Best Answer

You'll need to use a handler class for the views. FooTableViews like this: https://github.com/anomalylabs/addons-module/blob/2.2/src/Addon/Table/AddonTableViews.php#L39

label is the value and you can change context with context if needed (bootstrap contexts; info, success, danger, etc).

finnito  —  5 years ago

Nice! Works a treat - thanks again!