Answers.Body: <p>I can think of a couple ways to pull this off but Craft has many of the pieces already in place.</p>
  
  <ol>
  <li><p>I'd create a new Channel, name it <code>Organizations</code>. You can add whatever fields you want in there (like address, city, etc.)</p></li>
  <li><p>To leverage Craft's relations,  create a new field (<code>Organization</code>) that relates back to the <code>Organization</code> channel you just created and add it to the user's profile.</p></li>
  </ol>
  
  <p>That's the information architecture bit. It'd be up to you how you want to collect the information. Maybe when a user registers for their account for the first time, you'd ask for details. </p>
  
  <p>Then in a custom plugin, you'd probably want to validate to make sure the organization entry didn't already exist before creating a new entry in <code>Organizations</code> channel. Then set the relationship of that newly created entry to the User.</p>
  
  <p>The great thing about Craft is the UI is up to you. So you might use any number of <a href="http://tympanus.net/codrops/2009/10/03/33-javascript-solutions-for-sorting-tables/" rel="nofollow">table sorting plugins</a>. </p>
  
  <p>Craft can even handle the <a href="https://craftcms.com/docs/templating/paginate" rel="nofollow">Pagination</a> for you. I think <a href="https://www.datatables.net/examples/data_sources/server_side.html" rel="nofollow">DataTables</a> does ajax pagination out of the box, so your Twig template could just need to feed it the data.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-11T22:47:34.490Z
Answers.LastActivityDate: 2016-03-11T22:47:34.490Z
Answers.UserDisplayName: RitterKnight
Body: <p>I need to display a sortable table of organization member records in frontend, preferably with pagination. Before I start coding this from scratch, I want to ask:
  Does anyone have some ideas on how to do this, and what Craft/Yii/plugin functionality I could use to accomplish this?</p>
  
  <p>I'm fairly new to Craft, so at the moment I don't know where to start looking.</p>
  
  <p><strong>Some more details</strong><br>
  I'm writing a frontend customer portal plugin, that uses the built in Craft functionality for handling user registration/login/etc. On top of that I've added a <em>MyPlugin_UserRecord</em> and a <em>MyPlugin_OrganizationRecord</em> record, with some service functionality to handle those.<br></p>
  
  <p>The <em>MyPlugin_UserRecord</em> can be either a private user by it self, or belong to an organization as a member, and it's the latter that I want to display in the table.</p>
  
  <p>Below you can see the relations I have defined:</p>
  
  <pre><code>UserRecord (Craft)
  
  MyPlugin_OrganizationRecord
      'craft_user' =&gt; array(static::BELONGS_TO, 'UserRecord', 'craft_user_id'),
      'members' =&gt; array(static::HAS_MANY, 'MyPlugin_UserRecord', 'organization_id'),
  
  MyPlugin_UserRecord
      'craft_user' =&gt; array(static::BELONGS_TO, 'UserRecord', 'craft_user_id'),
      'organization' =&gt; array(static::BELONGS_TO, 'MyPlugin_OrganizationRecord', 'organization_id'),
  </code></pre>
  
Tags: <pagination><frontend><sorting><table>
Title: How to make a sortable table in frontend?
ThreadText: # How to make a sortable table in frontend?
  
  (Asked by: username_0 on 2016-03-11)
  
  I need to display a sortable table of organization member records in frontend, preferably with pagination. Before I start coding this from scratch, I want to ask:
  Does anyone have some ideas on how to do this, and what Craft/Yii/plugin functionality I could use to accomplish this?
  
  I'm fairly new to Craft, so at the moment I don't know where to start looking.
  
  **Some more details**  
  I'm writing a frontend customer portal plugin, that uses the built in Craft functionality for handling user registration/login/etc. On top of that I've added a *MyPlugin\_UserRecord* and a *MyPlugin\_OrganizationRecord* record, with some service functionality to handle those.
  
  The *MyPlugin\_UserRecord* can be either a private user by it self, or belong to an organization as a member, and it's the latter that I want to display in the table.
  
  Below you can see the relations I have defined:
  
  ```
  UserRecord (Craft)
  
  MyPlugin_OrganizationRecord
      'craft_user' => array(static::BELONGS_TO, 'UserRecord', 'craft_user_id'),
      'members' => array(static::HAS_MANY, 'MyPlugin_UserRecord', 'organization_id'),
  
  MyPlugin_UserRecord
      'craft_user' => array(static::BELONGS_TO, 'UserRecord', 'craft_user_id'),
      'organization' => array(static::BELONGS_TO, 'MyPlugin_OrganizationRecord', 'organization_id'),
  
  ```
  
  **Tags:** pagination, frontend, sorting, table
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-03-11. Score: 2
  
  I can think of a couple ways to pull this off but Craft has many of the pieces already in place.
  
  1. I'd create a new Channel, name it `Organizations`. You can add whatever fields you want in there (like address, city, etc.)
  2. To leverage Craft's relations, create a new field (`Organization`) that relates back to the `Organization` channel you just created and add it to the user's profile.
  
  That's the information architecture bit. It'd be up to you how you want to collect the information. Maybe when a user registers for their account for the first time, you'd ask for details.
  
  Then in a custom plugin, you'd probably want to validate to make sure the organization entry didn't already exist before creating a new entry in `Organizations` channel. Then set the relationship of that newly created entry to the User.
  
  The great thing about Craft is the UI is up to you. So you might use any number of [table sorting plugins](http://tympanus.net/codrops/2009/10/03/33-javascript-solutions-for-sorting-tables/).
  
  Craft can even handle the [Pagination](https://craftcms.com/docs/templating/paginate) for you. I think [DataTables](https://www.datatables.net/examples/data_sources/server_side.html) does ajax pagination out of the box, so your Twig template could just need to feed it the data.
  
  
  ---
  
  