1

I am writing a data tables plugin and am currently working on the index page in the CP.

I've followed the instructions here:

index.twig

{% extends '_layouts/elementindex' %}
{% set title = "DataTables"|t('app')  %}
{% set elementType = 'matfish\\DataTables\\elements\\DataTable' %}

{% block actionButton %}
 <div id="extra-headers">
    <div class="buttons right">
      <a href="{{ url('datatables/tables/new') }}" class="btn submit add icon">
       {{ "New DataTable"|t('datatables')}}
      </a>
    </div>
  </div>
{% endblock %}

Page is rendered but the table area is empty: enter image description here

Table Attributes are defined on element class, and are displayed in dropdown:

 protected static function defineTableAttributes(): array
    {
        return [
            'title' => \Craft::t('app', 'Title'),
            'elementType' => \Craft::t('datatables', 'Element Type'),
            'fields' => \Craft::t('datatables', 'Fields'),
        ];
    }

enter image description here

When I compared to other index pages I noticed that the ajax calls that are used to get the data and render the table are not fired:

index.php?p=admin/actions/element-indexes/get-elements&v=163847
index.php?p=admin/actions/element-indexes/count-elements&v=1638471423198

There are no JS errors in the console.


Edit 19-11-2022: Plugin ready at https://plugins.craftcms.com/tablecloth?craft4

1 Answer 1

2

There is no sources at the left side of your element index picture.

i think you missed source definition at your element type class:

it can be something simple like:

protected static function defineSources(string $context = null): array
{
    return [
        [
            'key' => '*',
            'label' => 'All Items',
            'criteria' => []
        ],
    ];
}

those requests are not fired because there is no criteria to pass via request without defining sources.

1
  • 1
    Thanks! One more thing I forgot was defining the query class on the find method. (craftcms.com/docs/3.x/extend/…). Without it Craft will just load all elements in the system.
    – Matanya
    Dec 3, 2021 at 6:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.