Jump to:

3376 Posts in 1000 Topics by 713 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Allow end user to filter data displayed

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 842 Views
  • mccarville
    Avatar
    Community Member
    32 Posts

    Allow end user to filter data displayed Link to this post

    I'm looking to allow users to filter the data that is displayed on a page based on a selection they are allowed to make [dropdown lists, check boxes, etc...]

    I can't seem to find any examples of how to pull this off.

    I know I could make a dataobject like the below

    class Staff extends Page {
       static $db = array(
       'Department' => "Enum('Math,Science','Math')",
       'LastName' => 'Text'

       );
       public static $has_one = array(

       );
       
       static $defaults = array (
    'ShowInMenus' => false
    );
       
    function getCMSFields() {
    $fields = parent::getCMSFields();
    $fields->addFieldToTab('Root.Content.Main', new DropdownField(
             'Department',
             'Select A Department:',
             singleton('Staff')->dbObject('Department')->enumValues()
          ),'Content');
       
    return $fields;
    }
    }

    class Staff_Controller extends Page_Controller {

    }

    And the use a page type like this to display the Math department

    class MathDept extends Page {
       static $db = array(
       );
       static $has_one = array(
    );
    static $allowed_children = array('Staff');

    }

    class MathDept_Controller extends Page_Controller {

    function DisplayMath(){
    $DM = DataObject::get("Staff", "Department = 'Math'", "LastName", null, null);
    return $DM;
    }

    }

    And then I could proceed to create a bunch of different page types for each department to display the departments, by changing the filter. Even while I type this I know that must be the most amature way to pull it off... =(

    I guess what I need to do is change Math in the where clause to a variable and some how allow the end user (not a CMS user) select the variable they want from from the page and click a "go" button or something of that sort. A live refresh would be in better but I have no idea how to pull this off.

    Any help would be greatly appreciated!!

    842 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.