Panel Performance issues with structure field (relations between entries)

I followed your idea of creating a custom multiselect, and it works beautifully — fast and with the same behavior as the default multiselect.

I created a simple plugin similar to what @steirico did:

// index.js
panel.plugin('user/multiselect-fast', {
    fields: {
        'multiselect-fast': {
            extends: 'k-multiselect-field',
        }
    }
});
// index.php
<?php

Kirby::plugin('user/multiselect-fast', [
    'fields' => [
        'multiselect-fast' => [
            'props' => [
                'type' => 'multiselect', // neccesary for correct display in structure column
                'options' => function () {
                    $page = page('pageSlugWithTheStructure');
                    
                    if (!$page) {
                        return [];
                    }

                    $items = $page->skills()->toStructure();
                    
                    $options = [];
                    foreach ($items as $item) {
                        $options[] = [
                            'value' => $item->title()->value,
                            'text' => $item->title()->value
                        ];
                    }

                    return $options;
                }
            ]
        ]
    ]
]);

And instead of using the default multiselect I use mine in the blueprint:

softwareSkill:
            label: Skills
            type: multiselect-fast

This keeps the panel snappy even with large datasets. Loading and Saving is in the realm of miliseconds again.

Honestly, I’m a bit surprised how simple the solution is. I’m not really into the nitty-gritty of the Kirby core, but why is the default multiselect handling this issue that different?

2 Likes