1

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'),
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.

Craft can even handle the Pagination for you. I think DataTables does ajax pagination out of the box, so your Twig template could just need to feed it the data.

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.