GetFilters not working for ListFilter types
I'm not sure if this is a bug or I am missing something. I am trying to save the view state for a datagrid to the session so when a user leaves the page and then returns his previous filters will be applied. I am following along with Vex's suggestions on this post. Everything works as expected with TextFilter types. When the filter is set to a ListFilter, when the user returns to the page, the filter is not set. I debugged and found that when the datagrid is filtered by the ListFilter GetFilters() returns an empty array. This is happening in both QCubed 1.1 and 2.02.
I have modified the Advanced QDatagrid Filtering example to display this behavior.
protected function Form_PreRender() {
$_SESSION['dtgProjects'] = array(
"PageNumber" => $this->dtgProjects->PageNumber,
"SortDirection" => $this->dtgProjects->SortDirection,
"SortColumnIndex" => $this->dtgProjects->SortColumnIndex,
"FilterInfo" => $this->dtgProjects->GetFilters()
);
}
protected function Form_Create() {
$this->dtgProjects_Create();
$this->dtgCustom_Create();
if(isset($_SESSION['dtgProjects'])){
$viewState = $_SESSION['dtgProjects'];
unset($_SESSION['dtgProjects']);
$this->dtgProjects->SetFilters($viewState['FilterInfo']);
$this->dtgProjects->SortColumnIndex = $viewState['SortColumnIndex'];
$this->dtgProjects->SortDirection = $viewState['SortDirection'];
$this->dtgProjects->PageNumber = $viewState['PageNumber'];
}
}
I was finally able to find the issue.
I had to change the GetFilters() and SetFilters() in QDataGridColumn.class.php. The fix works, but I am sure there is a better way of doing it.
GetFilters()
<?phppublic function GetFilters()
{
$filters = array();
foreach($this->objColumnArray as $col)
{
if(isset($col->FilterByCommand['value']))
{
//manual filter
$filterCommand = $col->FilterByCommand;
$filters[$col->Name] = $filterCommand['value'];
}
elseif($col->Filter !== null)
{
if($col->Filter instanceof QQConditionComparison)
{
//**** My Changes Here ****
// If FilterType is ListFilter return the SelectedName from the ListBox control.
// We will use this in SetFilters()
if($col->FilterType == QFilterType::ListFilter){
$filters[$col->Name] = $this->GetFilterControl($col)->SelectedName;
} else {
$filters[$col->Name] = $col->Filter;
}
}
else
throw new exception(QApplication::Translate("Unknown Filter type"));
}
}
return $filters;
}
?>
SetFilters()
<?phppublic function SetFilters($filters)
{
foreach($this->objColumnArray as $col)
{
if(isset($filters[$col->Name]))
{
if(null !== $col->FilterByCommand)
{
//if filterbycommand is used
$filterCommand = $col->FilterByCommand;
$filterCommand['value'] = $filters[$col->Name];
$col->FilterByCommand = $filterCommand;
}
//AddListItem with filters dont enter this check until filter button clicked
elseif($col->FilterType == QFilterType::TextFilter &&
$col->FilterList !== null && count($col->FilterList) == 1) {
if($col->FilterList[0] instanceof QQConditionComparison)
{
$col->Filter = $filters[$col->Name];
$col->FilterActivate();
}
}
elseif ($col->FilterType == QFilterType::ListFilter){
// If we set the columns Filter it looses it's FilterList
// Instead we will use FilterActivate and use the Columns name as the Index
//$col->Filter = $filters[$col->Name];
$col->FilterActivate($filters[$col->Name]);
}
}
}
}
?>
Hmm, I think that makes sense. Mind creating a ticket for this? :)
I will create the ticket later tonight.
Thanks. :)
Created Ticket #694