GetFilters not working for ListFilter types

Login or register to post comments
5 replies [Last post]
Steven Warren's picture
Offline
Joined: 11/06/2008

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'];
}
}

Steven Warren's picture
Offline
Joined: 11/06/2008

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()

<?php
public 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()

<?php
public 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]);
        }
    }
}
}
?>

Offline
Joined: 03/31/2008

Hmm, I think that makes sense. Mind creating a ticket for this? :)

Steven Warren's picture
Offline
Joined: 11/06/2008

I will create the ticket later tonight.

Offline
Joined: 03/31/2008

Thanks. :)

Steven Warren's picture
Offline
Joined: 11/06/2008

Created Ticket #694