Hi guys I'm trying to do this as well however I have taken a different approach. I have got my filter query that I want to use however I am not sure how to get this to work with my dropdown field. I have created a form with a dropdownfield where I want it to filter the list of dataobjects without reloading the page, so I need some sort of ajax functionality. I have set up a function that takes the parameter for the form. The function is using pagination but you get the idea it just needs to pass $data from the form and run the query, here it is:
public function CodeSnippetsforform($data) {
if(!isset($_GET['start']) || !is_numeric($_GET['start']) || (int)$_GET['start'] < 1) $_GET['start'] = 0;
$SQL_start = (int)$_GET['start'];
$doSet = DataObject::get(
$callerClass = "CodeSnippet",
$filter = "`ParentID` = '".$this->ID."' AND `CodeSnippet_Classifications`.ClassificationID = '".$data."'",
$sort = "SnipDate DESC",
$join = "LEFT JOIN `CodeSnippet_Classifications` ON `CodeSnippet`.ID = `CodeSnippet_Classifications`.CodeSnippetID",
$limit = "{$SQL_start},5");
return $doSet ? $doSet : false;
}
This is my code for the form:
public function SnipForm(){
$fields = new FieldSet(
new DropdownField(
'sortauth',
'Choose an Author',
Dataobject::get("Classification")->toDropdownMap("ID", "Title")
)
);
$actions = new FieldSet(
new FormAction('CodeSnippetsforform', 'Filter')
);
return new Form($this, 'SnipForm', $fields, $actions);
}
Another thing is that if I do it this way that I need to create some sort of a flag to allow for the function to only be run when the dropdownfield has been selected or to get it to run in a way that doesn't filter when the page loads because as you will see in my template I am running the function when the page loads which obviously crashes the query, here is the basic code that I'm using:
$SnipForm
<% control CodeSnippetsforform %>
<% end_control %>
So as you can see I'm missing ajax functionality and I am not sure what to do so any help will be appreciated.
Now I suspect that this could possibly be the complete wrong way to do this as I don't really understand the way you guys are doing it, perhaps you could show me your code for your form, or possibly if you or anyone can point me in the right direction to getting my method to work that would be great.
Thanks
Liam