Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Data Model Questions /

Allow end user to filter data displayed


Reply


996 Views

Avatar
mccarville

Community Member, 32 Posts

19 August 2009 at 10:54am

Edited: 19/08/2009 10:58am

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!!