Answers.Body: <p>You haven't defined any sources for your ElementType.</p>
  
  <pre><code>&lt;?php
  public function getSources($context = null)
  {
      $sources = [
          '*' =&gt; [
              'label' =&gt; Craft::t('All entries'),
              'criteria' =&gt; [],
              'defaultSort' =&gt; ['dateUpdated', 'desc']
          ]
      ];
  
      return $sources;
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-11T22:17:31.267Z
Answers.Text: Yep! Thanks for the help. Really wish they put a notice in the javascript log, at least when dev mode is on. Would have saved me hours :/
Answers.UserDisplayName: Rick Kukiela
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-20T11:00:38.100Z
Answers.Text: So annoying to always have one source to be defined. I don't want that sidebar :(
Answers.UserDisplayName: Bert Oost
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-11T21:52:59.883Z
Answers.LastActivityDate: 2017-05-11T21:52:59.883Z
Answers.UserDisplayName: Fred Carlsen
Body: <p>I can not for the life of me figure out why my cp page will not generate the elements table. On other elementtype pages in the cp there is an XHR request made to a controller called "getElements" and that returns the html for the elements table. On my elementtype page there is no XHR call and the page just sits there with no table.</p>
  
  <p>Here is my template twig:</p>
  
  <pre><code>{% extends "_layouts/elementindex" %}
  {% set title = "Pending Account Requests"|t %}
  {% set elementType = 'GrnPlatform_AccountRequest' %}
  </code></pre>
  
  <p>Here is my class for my element</p>
  
  <pre><code>namespace Craft;
  
  class GrnPlatform_AccountRequestElementType extends BaseElementType
  {
      public function getName()
      {
          return Craft::t('GRN Account Request');
      }
  
      public function defineTableAttributes()
      {
          return array(
              'firstName'         =&gt; Craft::t('First Name'),
              'lastName'          =&gt; Craft::t('Last Name'),
              'email'             =&gt; Craft::t('Email Address'),
              'roleRequested'     =&gt; Craft::t('Request For'),
              'dateCreated'       =&gt; Craft::t('Requested On')
          );
      }
  
      public function getTableAttributeHtml(BaseElementModel $element, $attribute)
      {
          switch ($attribute)
          {
              case 'dateCreated':
              {
                  $date = $element-&gt;$attribute;
  
                  if ($date)
                  {
                      return $date-&gt;localeDate();
                  }
                  else
                  {
                      return '';
                  }
              }
  
              default:
              {
                  return parent::getTableAttributeHtml($element, $attribute);
              }
          }
      }
  
      public function defineCriteriaAttributes()
      {
          return array(
              'userId'            =&gt; AttributeType::Number,
              'approved'          =&gt; AttributeType::Number,
              'denied'            =&gt; AttributeType::Number,
              'roleRequested'     =&gt; AttributeType::Mixed,
              'dateCreated'       =&gt; AttributeType::Mixed,
              'order'             =&gt; array(AttributeType::String, 'default' =&gt; 'requests.dateCreated asc')
          );
      }
  
      public function modifyElementsQuery(DbCommand $query, ElementCriteriaModel $criteria)
      {
          $query
              -&gt;addSelect('users.firstName, users.lastName, users.email, requests.roleRequested, requests.approved, requests.denied, requests.dateCreated')
              -&gt;Join('grnplatform_account_requests requests', 'requests.id = elements.id')
              -&gt;leftJoin('users users', 'users.id = requests.userId');
          if(isset($criteria-&gt;userId)) {
              $query-&gt;andWhere(DbHelper::parseParam('requests.userId', $criteria-&gt;userId, $query-&gt;params));
          }
          if(isset($criteria-&gt;roleRequested)) {
              $query-&gt;andWhere(DbHelper::parseParam('requests.roleRequested', $criteria-&gt;roleRequested, $query-&gt;params));
          }
          if(isset($criteria-&gt;dateCreated)) {
              $query-&gt;andWhere(DbHelper::parseParam('requests.dateCreated', $criteria-&gt;dateCreated, $query-&gt;params));
          }
          if(isset($criteria-&gt;approved)) {
              $query-&gt;andWhere(DbHelper::parseParam('requests.approved', $criteria-&gt;approved, $query-&gt;params));
          }
          if(isset($criteria-&gt;denied)) {
              $query-&gt;andWhere(DbHelper::parseParam('requests.denied', $criteria-&gt;denied, $query-&gt;params));
          }
      }
  
      public function populateElementModel($row)
      {
          return GrnPlatform_AccountRequestModel::populateModel($row);
      }
  
      public function getEditorHtml(BaseElementModel $element)
      {
          return parent::getEditorHtml($element);
      }
  }
  </code></pre>
  
  <p>Here is my plugin code for the route to the page:</p>
  
  <pre><code>public function registerCpRoutes()
  {
      return array(
          'grnplatform'                   =&gt; array('action' =&gt; 'GrnPlatform/mainIndex'),
          'grnplatform/AccountRequests'   =&gt; array('action' =&gt; 'GrnPlatform/AccountRequest/mainIndex')
      );
  }
  </code></pre>
  
  <p>Here is the controller that gets routed and renders the template:</p>
  
  <pre><code>namespace Craft;
  class GrnPlatform_AccountRequestController extends BaseController
  {
      public function actionMainIndex()
      {
  
          $this-&gt;renderTemplate('grnplatform/cp/account_requests');
      }
  }
  </code></pre>
  
  <p>Here is the ElementModel</p>
  
  <pre><code>namespace Craft;
  
  class GrnPlatform_AccountRequestModel extends BaseElementModel
  {
      protected $elementType = 'GrnPlatform_AccountRequest';
  
      public function __toString()
      {
          return ucfirst($this-&gt;getAttribute('roleRequested')) . " Request";
      }
  
      protected function defineAttributes()
      {
          return array_merge(parent::defineAttributes(), array(
              'userId'            =&gt; array("type" =&gt; AttributeType::Number, "required" =&gt; true),
              'roleRequested'     =&gt; array("type" =&gt; AttributeType::Enum, "values" =&gt; array("vendor", "facilitator"), "required" =&gt; true),
              'message'           =&gt; array("type" =&gt; AttributeType::String, 'required' =&gt; true),
              'completed'         =&gt; AttributeType::Bool,
              'approved'          =&gt; AttributeType::Bool,
              'denied'            =&gt; AttributeType::Bool
          ));
      }
  
      public function isEditable()
      {
          return true;
      }
  
      public function getCpEditUrl()
      {
      }
  
      public function getFieldLayout()
      {
          return null;
      }
  }
  </code></pre>
  
  <p>Here is the Record for the element:</p>
  
  <pre><code>namespace Craft;
  
  class GrnPlatform_AccountRequestRecord extends BaseRecord
  {
      public function getTableName()
      {
          return 'grnplatform_account_requests';
      }
  
     protected function defineAttributes()
      {
          return array(
              'userId'        =&gt; array(AttributeType::Number, 'required' =&gt; true),
              'roleRequested' =&gt; array(AttributeType::Enum, 'values' =&gt; array('vendor','facilitator'), 'required' =&gt; true),
              'message'       =&gt; array(AttributeType::String, 'column' =&gt; ColumnType::Text, 'required' =&gt; true),
              'denied'        =&gt; AttributeType::Bool,
              'approved'      =&gt; AttributeType::Bool
          );
      }
  
      public function defineRelations()
      {
          return array(
              'element'  =&gt; array(static::BELONGS_TO, 'ElementRecord', 'id', 'required' =&gt; true, 'onDelete' =&gt; static::CASCADE),
              'user' =&gt; array(static::BELONGS_TO, 'UserRecord', 'userId', 'onDelete' =&gt; static::CASCADE)
          );
      }
  
      public function defineIndexes()
      {
          return array(
              array('columns'=&gt;array('roleRequested'), 'unique' =&gt; false),
              array('columns'=&gt;array('denied'), 'unique' =&gt; false),
              array('columns'=&gt;array('approved'), 'unique' =&gt; false),
              array('columns'=&gt;array('userId'), 'unique' =&gt; false)
          );
      }
  }
  </code></pre>
  
  <p><em>EDIT 1</em> </p>
  
  <p>I did some manual debugging through the JS on the page and I found this inside the <code>Craft.baseElementIndex:init()</code> function:</p>
  
  <pre><code>// No source, no party.
  if ($sources.length == 0)
  {
      return;
  } 
  </code></pre>
  
  <p>My code is hitting this because I dont have any sources... Honestly I'm not even sure what my sources would be in this instance...</p>
  
Tags: <plugin-development><control-panel><elementtype>
Title: ElementType CP section does not display table
ThreadText: # ElementType CP section does not display table
  
  (Asked by: username_0 on 2017-05-11)
  
  I can not for the life of me figure out why my cp page will not generate the elements table. On other elementtype pages in the cp there is an XHR request made to a controller called "getElements" and that returns the html for the elements table. On my elementtype page there is no XHR call and the page just sits there with no table.
  
  Here is my template twig:
  
  ```
  {% extends "_layouts/elementindex" %}
  {% set title = "Pending Account Requests"|t %}
  {% set elementType = 'GrnPlatform_AccountRequest' %}
  
  ```
  
  Here is my class for my element
  
  ```
  namespace Craft;
  
  class GrnPlatform_AccountRequestElementType extends BaseElementType
  {
      public function getName()
      {
          return Craft::t('GRN Account Request');
      }
  
      public function defineTableAttributes()
      {
          return array(
              'firstName'         => Craft::t('First Name'),
              'lastName'          => Craft::t('Last Name'),
              'email'             => Craft::t('Email Address'),
              'roleRequested'     => Craft::t('Request For'),
              'dateCreated'       => Craft::t('Requested On')
          );
      }
  
      public function getTableAttributeHtml(BaseElementModel $element, $attribute)
      {
          switch ($attribute)
          {
              case 'dateCreated':
              {
                  $date = $element->$attribute;
  
                  if ($date)
                  {
                      return $date->localeDate();
                  }
                  else
                  {
                      return '';
                  }
              }
  
              default:
              {
                  return parent::getTableAttributeHtml($element, $attribute);
              }
          }
      }
  
      public function defineCriteriaAttributes()
      {
          return array(
              'userId'            => AttributeType::Number,
              'approved'          => AttributeType::Number,
              'denied'            => AttributeType::Number,
              'roleRequested'     => AttributeType::Mixed,
              'dateCreated'       => AttributeType::Mixed,
              'order'             => array(AttributeType::String, 'default' => 'requests.dateCreated asc')
          );
      }
  
      public function modifyElementsQuery(DbCommand $query, ElementCriteriaModel $criteria)
      {
          $query
              ->addSelect('users.firstName, users.lastName, users.email, requests.roleRequested, requests.approved, requests.denied, requests.dateCreated')
              ->Join('grnplatform_account_requests requests', 'requests.id = elements.id')
              ->leftJoin('users users', 'users.id = requests.userId');
          if(isset($criteria->userId)) {
              $query->andWhere(DbHelper::parseParam('requests.userId', $criteria->userId, $query->params));
          }
          if(isset($criteria->roleRequested)) {
              $query->andWhere(DbHelper::parseParam('requests.roleRequested', $criteria->roleRequested, $query->params));
          }
          if(isset($criteria->dateCreated)) {
              $query->andWhere(DbHelper::parseParam('requests.dateCreated', $criteria->dateCreated, $query->params));
          }
          if(isset($criteria->approved)) {
              $query->andWhere(DbHelper::parseParam('requests.approved', $criteria->approved, $query->params));
          }
          if(isset($criteria->denied)) {
              $query->andWhere(DbHelper::parseParam('requests.denied', $criteria->denied, $query->params));
          }
      }
  
      public function populateElementModel($row)
      {
          return GrnPlatform_AccountRequestModel::populateModel($row);
      }
  
      public function getEditorHtml(BaseElementModel $element)
      {
          return parent::getEditorHtml($element);
      }
  }
  
  ```
  
  Here is my plugin code for the route to the page:
  
  ```
  public function registerCpRoutes()
  {
      return array(
          'grnplatform'                   => array('action' => 'GrnPlatform/mainIndex'),
          'grnplatform/AccountRequests'   => array('action' => 'GrnPlatform/AccountRequest/mainIndex')
      );
  }
  
  ```
  
  Here is the controller that gets routed and renders the template:
  
  ```
  namespace Craft;
  class GrnPlatform_AccountRequestController extends BaseController
  {
      public function actionMainIndex()
      {
  
          $this->renderTemplate('grnplatform/cp/account_requests');
      }
  }
  
  ```
  
  Here is the ElementModel
  
  ```
  namespace Craft;
  
  class GrnPlatform_AccountRequestModel extends BaseElementModel
  {
      protected $elementType = 'GrnPlatform_AccountRequest';
  
      public function __toString()
      {
          return ucfirst($this->getAttribute('roleRequested')) . " Request";
      }
  
      protected function defineAttributes()
      {
          return array_merge(parent::defineAttributes(), array(
              'userId'            => array("type" => AttributeType::Number, "required" => true),
              'roleRequested'     => array("type" => AttributeType::Enum, "values" => array("vendor", "facilitator"), "required" => true),
              'message'           => array("type" => AttributeType::String, 'required' => true),
              'completed'         => AttributeType::Bool,
              'approved'          => AttributeType::Bool,
              'denied'            => AttributeType::Bool
          ));
      }
  
      public function isEditable()
      {
          return true;
      }
  
      public function getCpEditUrl()
      {
      }
  
      public function getFieldLayout()
      {
          return null;
      }
  }
  
  ```
  
  Here is the Record for the element:
  
  ```
  namespace Craft;
  
  class GrnPlatform_AccountRequestRecord extends BaseRecord
  {
      public function getTableName()
      {
          return 'grnplatform_account_requests';
      }
  
     protected function defineAttributes()
      {
          return array(
              'userId'        => array(AttributeType::Number, 'required' => true),
              'roleRequested' => array(AttributeType::Enum, 'values' => array('vendor','facilitator'), 'required' => true),
              'message'       => array(AttributeType::String, 'column' => ColumnType::Text, 'required' => true),
              'denied'        => AttributeType::Bool,
              'approved'      => AttributeType::Bool
          );
      }
  
      public function defineRelations()
      {
          return array(
              'element'  => array(static::BELONGS_TO, 'ElementRecord', 'id', 'required' => true, 'onDelete' => static::CASCADE),
              'user' => array(static::BELONGS_TO, 'UserRecord', 'userId', 'onDelete' => static::CASCADE)
          );
      }
  
      public function defineIndexes()
      {
          return array(
              array('columns'=>array('roleRequested'), 'unique' => false),
              array('columns'=>array('denied'), 'unique' => false),
              array('columns'=>array('approved'), 'unique' => false),
              array('columns'=>array('userId'), 'unique' => false)
          );
      }
  }
  
  ```
  
  *EDIT 1*
  
  I did some manual debugging through the JS on the page and I found this inside the `Craft.baseElementIndex:init()` function:
  
  ```
  // No source, no party.
  if ($sources.length == 0)
  {
      return;
  } 
  
  ```
  
  My code is hitting this because I dont have any sources... Honestly I'm not even sure what my sources would be in this instance...
  
  **Tags:** plugin-development, control-panel, elementtype
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-05-11. Score: 5 | Accepted answer
  
  You haven't defined any sources for your ElementType.
  
  ```
  <?php
  public function getSources($context = null)
  {
      $sources = [
          '*' => [
              'label' => Craft::t('All entries'),
              'criteria' => [],
              'defaultSort' => ['dateUpdated', 'desc']
          ]
      ];
  
      return $sources;
  }
  
  ```
  
  > **Comments:**
  > **username_0**: Yep! Thanks for the help. Really wish they put a notice in the javascript log, at least when dev mode is on. Would have saved me hours :/  
  > **username_2**: So annoying to always have one source to be defined. I don't want that sidebar :(  
  
  ---
  
  